[sheepdog] [PATCH] tests: ensure that sheeps are not running if necessary

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed Sep 5 09:58:44 CEST 2012


This ensures that sheeps are not running when
 - starting a testcase
 - unmounting devices
 - starting a sheep daemon

This removes a lot of false test errors.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 tests/011       |    5 +++--
 tests/032       |    2 +-
 tests/033       |    2 +-
 tests/common.rc |   29 +++++++++++++++++++++++++++--
 4 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/tests/011 b/tests/011
index 975c283..13df80f 100755
--- a/tests/011
+++ b/tests/011
@@ -17,8 +17,9 @@ trap "_cleanup_devices; exit \$status" 0 1 2 3 15
 
 _cleanup_devices()
 {
-    killall -9 sheep collie >/dev/null 2>&1 || true
-    sleep 2
+    killall -9 collie >/dev/null 2>&1 || true
+    _kill_all_sheeps
+
     for i in 0 1 2; do
         umount $STORE/$i
         rm -f $STORE/$i.img
diff --git a/tests/032 b/tests/032
index 094ec13..259e798 100755
--- a/tests/032
+++ b/tests/032
@@ -41,7 +41,7 @@ sleep 1
 # start master first to avoid master transfer
 _start_sheep 0
 _wait_for_sheep 1
-for i in `seq 0 7`; do
+for i in `seq 1 7`; do
     _start_sheep $i
 done
 
diff --git a/tests/033 b/tests/033
index e5355b0..93d8314 100755
--- a/tests/033
+++ b/tests/033
@@ -45,7 +45,7 @@ sleep 1
 # start master first
 _start_sheep 0
 _wait_for_sheep 1
-for i in `seq 0 7`; do
+for i in `seq 1 7`; do
     _start_sheep $i
 done
 
diff --git a/tests/common.rc b/tests/common.rc
index 9893b29..5faa6dd 100644
--- a/tests/common.rc
+++ b/tests/common.rc
@@ -120,8 +120,9 @@ _die()
 
 _cleanup()
 {
-    killall -9 sheep collie >/dev/null 2>&1 || true
-    sleep 1
+    killall -9 collie >/dev/null 2>&1 || true
+    _kill_all_sheeps
+
     mkdir -p $STORE
     for i in $STORE/?; do
         rm -rf $i
@@ -177,6 +178,21 @@ _wait_for_sheep()
 
 _start_sheep()
 {
+    # ensure that sheep is not running
+    running=true
+    for cnt in `seq 1 10`; do  # wait at most 10 seconds
+        pgrep -f "$SHEEP_PROG $STORE/$1" > /dev/null
+        if [ $? != 0 ]; then
+            running=false
+            break
+        fi
+        sleep 1
+    done
+
+    if $running; then
+        _die "sheep $1 is still running"
+    fi
+
     $SHEEP $STORE/$1 -z $1 -p $((7000+$1)) -c $DRIVER -y 127.0.0.1 -d $2
 
     if [ $? != 0 ]; then
@@ -184,6 +200,15 @@ _start_sheep()
     fi
 }
 
+_kill_all_sheeps()
+{
+    pkill -9 -f "$SHEEP_PROG $STORE"
+
+    while [ $? == 0 ]; do
+        pgrep -f "$SHEEP_PROG $STORE" > /dev/null
+    done
+}
+
 _kill_sheep()
 {
     pkill -9 -f "$SHEEP $STORE/$1"
-- 
1.7.2.5




More information about the sheepdog mailing list