[sheepdog] [PATCH 1/8] test: teach test framework to test zookeeper driver

Liu Yuan namei.unix at gmail.com
Sun Dec 23 16:26:24 CET 2012


From: Liu Yuan <tailai.ly at taobao.com>

to test zookeeper:
 root# ./check -zk

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 tests/001       |    8 +++-----
 tests/002       |    1 +
 tests/004       |    4 ++--
 tests/005       |   11 ++++++++---
 tests/007       |    9 +++++----
 tests/008       |    4 ++++
 tests/015       |    1 +
 tests/024       |   18 ++++++++++--------
 tests/026       |    7 +++++++
 tests/031       |    2 +-
 tests/034       |    6 ++++++
 tests/044       |    4 ++++
 tests/048       |    1 +
 tests/049       |    2 +-
 tests/HOWTO     |    2 ++
 tests/check     |    6 ++++++
 tests/common.rc |   18 +++++++++++++++---
 17 files changed, 77 insertions(+), 27 deletions(-)

diff --git a/tests/001 b/tests/001
index 2e6848b..40ef849 100755
--- a/tests/001
+++ b/tests/001
@@ -17,7 +17,6 @@ _cleanup
 
 for i in 0 1; do
     _start_sheep $i
-    sleep 1
 done
 
 _wait_for_sheep 2
@@ -32,12 +31,12 @@ sleep 1
 
 # start another sheep
 _start_sheep 2
-sleep 1
+_wait_for_sheep 2 2
 
 # kill all sheeps
 for i in 1 2; do
     _kill_sheep $i
-    sleep 2
+    sleep 1
 done
 
 for i in 0 1 2; do
@@ -45,17 +44,16 @@ for i in 0 1 2; do
     sleep 1
 done
 
+_wait_for_sheep 1 2
 echo check whether Sheepdog is running with only one node
 $COLLIE cluster info -p 7002 | _filter_cluster_info
 
 # add the other nodes
 for i in 0 1; do
     _start_sheep $i
-    sleep 1
 done
 
 _wait_for_sheep 3
-
 echo check whether all nodes have the same cluster info
 for i in 0 1 2; do
     $COLLIE cluster info -p 700$i | _filter_cluster_info
diff --git a/tests/002 b/tests/002
index 39be8ea..c8ab2b6 100755
--- a/tests/002
+++ b/tests/002
@@ -43,6 +43,7 @@ $COLLIE cluster info -p 7002 | _filter_cluster_info
 # add the other nodes
 for i in 0 1; do
     _start_sheep $i
+    sleep 1
 done
 
 _wait_for_sheep 3
diff --git a/tests/004 b/tests/004
index 1cb99fc..6c1c95b 100755
--- a/tests/004
+++ b/tests/004
@@ -17,9 +17,9 @@ _cleanup
 
 for i in 0 1; do
     _start_sheep $i
-    sleep 1
 done
 
+_wait_for_sheep 2
 # start Sheepdog with two nodes
 $COLLIE cluster format -c 2
 
@@ -29,7 +29,7 @@ for i in 2 3 4; do
     sleep 1
 
     _start_sheep $i
-    sleep 1
+    sleep 2
 done
 
 # kill all existing nodes
diff --git a/tests/005 b/tests/005
index 3e178a7..9a6980f 100755
--- a/tests/005
+++ b/tests/005
@@ -17,9 +17,9 @@ _cleanup
 
 for i in 0 1; do
     _start_sheep $i
-    sleep 1
 done
 
+_wait_for_sheep 2
 # start Sheepdog with two nodes
 $COLLIE cluster format -c 1
 sleep 1
@@ -28,17 +28,21 @@ for i in 2 3 4; do
     _kill_sheep $((i - 2))
     sleep 1
     _start_sheep $i
-    sleep 1
+    sleep 2
 done
 
+_wait_for_sheep 2 4
+
 $COLLIE cluster shutdown -p 7004
-sleep 1
+sleep 2
 
 for i in 0 1 2 3 4; do
     _start_sheep $i
     sleep 1
 done
 
+_wait_for_sheep 2 4
+
 echo check whether Sheepdog is working with two nodes
 for i in 3 4; do
     $COLLIE cluster info -p 700$i | _filter_cluster_info
@@ -50,6 +54,7 @@ for i in 0 1 2; do
     sleep 1
 done
 
+_wait_for_sheep 5
 echo check whether all nodes have the same cluster info
 for i in 0 1 2 3 4; do
     $COLLIE cluster info -p 700$i | _filter_cluster_info
diff --git a/tests/007 b/tests/007
index 72ca3ce..8253d20 100755
--- a/tests/007
+++ b/tests/007
@@ -18,20 +18,21 @@ _cleanup
 
 # create a node who has wrong epoch
 _start_sheep 1
-sleep 1
+_wait_for_sheep 1 1
 $COLLIE cluster format -p 7001 -c 1
 $COLLIE cluster shutdown -p 7001
-sleep 1
+sleep 2
 
 # start Sheepdog with one node
 _start_sheep 0
-sleep 1
+_wait_for_sheep 1
 $COLLIE cluster format -p 7000 -c 1
 
 for i in `seq 0 5`; do
     _start_sheep 1  # should fail
-    _start_sheep 2  # should succeed
     sleep 1
+    _start_sheep 2  # should succeed
+    _wait_for_sheep 2
 
     if [ "`$COLLIE node list -p 7002 -r | wc -l`" -ne 2 ]; then
 	echo "test failed"
diff --git a/tests/008 b/tests/008
index b2ecc43..cd2f2b6 100755
--- a/tests/008
+++ b/tests/008
@@ -13,6 +13,10 @@ status=1        # failure is the default!
 . ./common.rc
 . ./common.filter
 
+if [[ "$DRIVER" == zoo* ]];then
+    DRIVER=${DRIVER/1000/5000}
+fi
+
 _cleanup
 
 for i in `seq 0 7`; do
diff --git a/tests/015 b/tests/015
index 9c980cb..d3bd1e3 100755
--- a/tests/015
+++ b/tests/015
@@ -22,6 +22,7 @@ done
 _wait_for_sheep 2
 
 $COLLIE cluster format -c 2
+sleep 1
 $COLLIE vdi create test 539545600
 $COLLIE vdi setattr test lock 1 -x &
 $COLLIE vdi setattr test lock 1 -x &
diff --git a/tests/024 b/tests/024
index 6738b4b..f8668f0 100755
--- a/tests/024
+++ b/tests/024
@@ -15,20 +15,24 @@ status=1        # failure is the default!
 
 _cleanup
 
+if [[ "$DRIVER" == zoo* ]];then
+	DRIVER=${DRIVER/1000/5000}
+fi
+
 VDI_NAME="test"
 VDI_SIZE="300M"
 
 echo "starting first sheep"
-for i in `seq 0 0`; do
-    _start_sheep $i
-done
-_wait_for_sheep "1"
+_start_sheep 0
+_wait_for_sheep 1
 
 echo "formatting cluster"
 $COLLIE cluster format -c 1
+sleep 1
 
 echo "creating vdi ${NAME}"
 $COLLIE vdi create ${VDI_NAME} ${VDI_SIZE}
+sleep 1
 
 echo "filling ${VDI_NAME} with data"
 qemu-io -c "write 0 ${VDI_SIZE}" sheepdog:${VDI_NAME} | _filter_qemu_io
@@ -37,10 +41,8 @@ echo "reading back ${VDI_NAME}"
 qemu-io -c "read 0 1m" sheepdog:${VDI_NAME} | _filter_qemu_io
 
 echo "starting second sheep"
-for i in `seq 1 1`; do
-    _start_sheep $i
-done
-_wait_for_sheep "2"
+_start_sheep 1
+_wait_for_sheep 2
 
 echo "reading data from second sheep"
 qemu-io -c "read 0 ${VDI_SIZE}" sheepdog:localhost:7001:${VDI_NAME} | _filter_qemu_io
diff --git a/tests/026 b/tests/026
index 128cf09..9843e22 100755
--- a/tests/026
+++ b/tests/026
@@ -15,6 +15,10 @@ status=1        # failure is the default!
 
 _cleanup
 
+if [[ "$DRIVER" == zoo* ]];then
+    DRIVER=${DRIVER/1000/5000}
+fi
+
 for i in `seq 0 7`; do
     _start_sheep $i
 done
@@ -32,10 +36,13 @@ done
 
 # kill nodes and join them back
 for i in 1 2; do _kill_sheep $i;done
+sleep 3
 _wait_for_sheep_recovery 0
 for i in 3 4; do _kill_sheep $i;done
+sleep 3
 _wait_for_sheep_recovery 0
 for i in 5; do _kill_sheep $i;done
+sleep 3
 _wait_for_sheep_recovery 0
 for i in `seq 1 5`; do _start_sheep $i;done
 
diff --git a/tests/031 b/tests/031
index 44ef34f..0f3f550 100755
--- a/tests/031
+++ b/tests/031
@@ -27,7 +27,7 @@ done
 $COLLIE vdi list | _filter_short_date
 
 $COLLIE cluster shutdown
-sleep 1
+sleep 2
 
 _start_sheep 0
 _wait_for_sheep 1
diff --git a/tests/034 b/tests/034
index c0ad374..be80633 100755
--- a/tests/034
+++ b/tests/034
@@ -15,6 +15,10 @@ status=1        # failure is the default!
 
 _cleanup
 
+if [[ "$DRIVER" == zoo* ]];then
+    DRIVER=${DRIVER/1000/5000}
+fi
+
 # start 8 nodes
 for i in `seq 0 7`; do
     _start_sheep $i
@@ -23,6 +27,7 @@ done
 _wait_for_sheep 8
 
 $COLLIE cluster format
+sleep 1
 
 $COLLIE vdi create test 100MB
 # create 25 objects
@@ -34,6 +39,7 @@ done
 for i in `seq 3 7`; do
     _wait_for_sheep_recovery 0
     _kill_sheep $i
+    sleep 3
 done
 
 # update vdi
diff --git a/tests/044 b/tests/044
index 6f5705c..dcb8be3 100755
--- a/tests/044
+++ b/tests/044
@@ -13,6 +13,10 @@ status=1        # failure is the default!
 . ./common.rc
 . ./common.filter
 
+if [[ "$DRIVER" == zoo* ]];then
+    DRIVER=${DRIVER/1000/5000}
+fi
+
 _cleanup
 
 for i in 0 1 2; do
diff --git a/tests/048 b/tests/048
index 51c6fe2..34695cf 100755
--- a/tests/048
+++ b/tests/048
@@ -29,6 +29,7 @@ $COLLIE vdi create test 1G
 echo hello | $COLLIE vdi write test 4M 512
 # kill the master gracefully
 $COLLIE node kill 0
+sleep 2
 _wait_for_sheep_recovery 1
 $COLLIE node list -p 7001
 
diff --git a/tests/049 b/tests/049
index 9174d31..79b9bd7 100755
--- a/tests/049
+++ b/tests/049
@@ -28,7 +28,7 @@ $COLLIE vdi create test 20M
 dd if=/dev/urandom | $COLLIE vdi write -w test
 
 $COLLIE cluster shutdown
-sleep 1
+sleep 2
 
 #trigger an object reclaim at startup
 for i in `seq 0 2`; do
diff --git a/tests/HOWTO b/tests/HOWTO
index 98b6387..db4966c 100644
--- a/tests/HOWTO
+++ b/tests/HOWTO
@@ -8,3 +8,5 @@ Running tests:
       See the 'group' file for details on groups
       For e.g, './check -g quick' run tests grouped as 'quick'
     - To randomize test order: ./check -r [test(s)]
+
+To test zookeeper, you should set tickTime=500 first at zoo.cfg.
diff --git a/tests/check b/tests/check
index c5311a4..9f47aeb 100755
--- a/tests/check
+++ b/tests/check
@@ -138,6 +138,7 @@ common options
 check options
     -sheepdog           test sheepdog
     -corosync           use corosync driver (default: local)
+    -zk                 use zookeeper driver
     -valgrind           use valgrind
     -xdiff		graphical mode diff
     -e			exit immediately on test failure
@@ -159,6 +160,11 @@ testlist options
 	    xpand=false
 	    ;;
 
+	-zk)
+	    DRIVER="zookeeper:localhost:2181,timeout=1000"
+	    xpand=false
+	    ;;
+
 	-valgrind)
 	    valgrind=true
 	    xpand=false
diff --git a/tests/common.rc b/tests/common.rc
index 7ee1b71..914be32 100644
--- a/tests/common.rc
+++ b/tests/common.rc
@@ -132,6 +132,10 @@ _cleanup()
     for i in $STORE/??; do
         rm -rf $i
     done
+
+    if [[ "$DRIVER" == zoo* ]];then
+        sleep 5 # wait for zookeeper ephemeral node to be deleted
+    fi
 }
 
 _count_sheep_processes()
@@ -142,14 +146,18 @@ _count_sheep_processes()
 # wait for all sheep to join completely
 _wait_for_sheep()
 {
+    PORT=7000
+    if [ $2 ]; then
+        PORT=$((7000 + $2))
+    fi
     while true; do
-        sleep 1
+        sleep 2
 
         if [ $(_count_sheep_processes) != $1 ]; then
-            _die "there are not enough sheep processes"
+            _die "should have $1, but have $(_count_sheep_processes) sheep"
         fi
 
-        node_list="$($COLLIE node list 2> /dev/null)"
+        node_list="$($COLLIE node list -p $PORT 2> /dev/null)"
 
         if [ $? != 0 ]; then
             # sheep is not ready yet
@@ -249,6 +257,10 @@ _kill_sheep()
     while [ $? == 0 ]; do
 	pgrep -f "$SHEEP_PROG $STORE/$1" > /dev/null
     done
+
+    if [[ "$DRIVER" == zoo* ]];then
+        sleep 3 # wait for zookeeper ephemeral node to be deleted
+    fi
 }
 
 _wait_for_sheep_recovery()
-- 
1.7.9.5




More information about the sheepdog mailing list