From 193e6037407cd4c2cdd5ed1f4a90a79e9a2515f1 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 25 Oct 2017 12:04:49 +1100 Subject: [PATCH 1/5] ctdb-tests: Allow wait_until() to be used in unit tests BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit d69899238bfe468cd3e915f6d66e279811301d66) --- ctdb/tests/scripts/common.sh | 44 +++++++++++++++++++++++++++++++++++++ ctdb/tests/scripts/integration.bash | 44 ------------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/ctdb/tests/scripts/common.sh b/ctdb/tests/scripts/common.sh index 287fb71fd1d..e20b6d0ee7e 100644 --- a/ctdb/tests/scripts/common.sh +++ b/ctdb/tests/scripts/common.sh @@ -43,3 +43,47 @@ die () { echo "$1" >&2 ; exit ${2:-1} } + +# Wait until either timeout expires or command succeeds. The command +# will be tried once per second, unless timeout has format T/I, where +# I is the recheck interval. +wait_until () +{ + local timeout="$1" ; shift # "$@" is the command... + + local interval=1 + case "$timeout" in + */*) + interval="${timeout#*/}" + timeout="${timeout%/*}" + esac + + local negate=false + if [ "$1" = "!" ] ; then + negate=true + shift + fi + + echo -n "<${timeout}|" + local t=$timeout + while [ $t -gt 0 ] ; do + local rc=0 + "$@" || rc=$? + if { ! $negate && [ $rc -eq 0 ] ; } || \ + { $negate && [ $rc -ne 0 ] ; } ; then + echo "|$(($timeout - $t))|" + echo "OK" + return 0 + fi + local i + for i in $(seq 1 $interval) ; do + echo -n . + done + t=$(($t - $interval)) + sleep $interval + done + + echo "*TIMEOUT*" + + return 1 +} diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash index b2a3451049c..86dbbdc9083 100644 --- a/ctdb/tests/scripts/integration.bash +++ b/ctdb/tests/scripts/integration.bash @@ -259,50 +259,6 @@ delete_ip_from_all_nodes () ####################################### -# Wait until either timeout expires or command succeeds. The command -# will be tried once per second, unless timeout has format T/I, where -# I is the recheck interval. -wait_until () -{ - local timeout="$1" ; shift # "$@" is the command... - - local interval=1 - case "$timeout" in - */*) - interval="${timeout#*/}" - timeout="${timeout%/*}" - esac - - local negate=false - if [ "$1" = "!" ] ; then - negate=true - shift - fi - - echo -n "<${timeout}|" - local t=$timeout - while [ $t -gt 0 ] ; do - local rc=0 - "$@" || rc=$? - if { ! $negate && [ $rc -eq 0 ] ; } || \ - { $negate && [ $rc -ne 0 ] ; } ; then - echo "|$(($timeout - $t))|" - echo "OK" - return 0 - fi - local i - for i in $(seq 1 $interval) ; do - echo -n . - done - t=$(($t - $interval)) - sleep $interval - done - - echo "*TIMEOUT*" - - return 1 -} - sleep_for () { echo -n "=${1}|" -- 2.14.2 From 8b2be954406de5755aef8e39fe4da89ea6cfb78a Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 25 Oct 2017 18:52:10 +1100 Subject: [PATCH 2/5] ctdb-tests: Wait for ctdb_eventd to start, fail if it doesn't BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit dcbaebc232b49e6a64228f1bb7ce7cfc5d2120e2) --- ctdb/tests/eventd/scripts/local.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ctdb/tests/eventd/scripts/local.sh b/ctdb/tests/eventd/scripts/local.sh index 343205ecec4..c8f7775f554 100644 --- a/ctdb/tests/eventd/scripts/local.sh +++ b/ctdb/tests/eventd/scripts/local.sh @@ -42,7 +42,7 @@ cleanup_eventd () setup_eventd () { - debug "Setting up eventd" + echo "Setting up eventd" if [ -n "$1" ]; then extra_args="-D $1" @@ -53,9 +53,8 @@ setup_eventd () -e "$eventd_scriptdir" \ -l "file:" -d "DEBUG" $extra_args 2>&1 | tee "$eventd_logfile" & # Wait till eventd is running - while [ ! -S "$eventd_socket" ] ; do - sleep 1 - done + wait_until 10 test -S "$eventd_socket" || \ + die "ctdb_eventd failed to start" test_cleanup cleanup_eventd } -- 2.14.2 From 2852483461e97228d163fa8c4122df923881e37b Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 25 Oct 2017 21:43:56 +1100 Subject: [PATCH 3/5] ctdb-tests: Skip starting fake_ctdbd when current node is disconnected BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 274fef9b843aa1726c9d331a876504bc0a96a322) --- ctdb/tests/tool/ctdb.getcapabilities.003.sh | 13 +++++++------ ctdb/tests/tool/ctdb.lvs.008.sh | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ctdb/tests/tool/ctdb.getcapabilities.003.sh b/ctdb/tests/tool/ctdb.getcapabilities.003.sh index 91d38b8c9e3..74702d5b5e7 100755 --- a/ctdb/tests/tool/ctdb.getcapabilities.003.sh +++ b/ctdb/tests/tool/ctdb.getcapabilities.003.sh @@ -10,12 +10,13 @@ setup_nodes < Date: Wed, 25 Oct 2017 17:52:04 +1100 Subject: [PATCH 4/5] ctdb-tests: Wait for fake_ctdbd to start, fail if it doesn't BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 6fad42103c0c812d5b5f4b42854fd7fd68846487) --- ctdb/tests/tool/scripts/local.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ctdb/tests/tool/scripts/local.sh b/ctdb/tests/tool/scripts/local.sh index 2c9be2d324c..7cee84a2d4b 100644 --- a/ctdb/tests/tool/scripts/local.sh +++ b/ctdb/tests/tool/scripts/local.sh @@ -48,10 +48,14 @@ cleanup_ctdbd () setup_ctdbd () { - debug "Setting up fake ctdbd" + echo "Setting up fake ctdbd" $VALGRIND fake_ctdbd -d "$FAKE_CTDBD_DEBUGLEVEL" \ -s "$ctdbd_socket" -p "$ctdbd_pidfile" + # Wait till fake_ctdbd is running + wait_until 10 test -S "$ctdbd_socket" || \ + die "fake_ctdbd failed to start" + test_cleanup cleanup_ctdbd } -- 2.14.2 From 925650c6801b3c5583c73144670b3f5d08c80919 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 25 Oct 2017 12:15:23 +1100 Subject: [PATCH 5/5] ctdb-tests: Process-exists unit tests should wait until PID is registered Otherwise the client registration can race with the check in the test. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13097 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs Autobuild-User(master): Amitay Isaacs Autobuild-Date(master): Thu Oct 26 13:32:24 CEST 2017 on sn-devel-144 (cherry picked from commit 0e8b781e0740310d251bf1fa7db7a467d4f7f9b5) --- ctdb/tests/tool/ctdb.process-exists.001.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctdb/tests/tool/ctdb.process-exists.001.sh b/ctdb/tests/tool/ctdb.process-exists.001.sh index 2339344fec5..1b6d213b3ad 100755 --- a/ctdb/tests/tool/ctdb.process-exists.001.sh +++ b/ctdb/tests/tool/ctdb.process-exists.001.sh @@ -14,6 +14,8 @@ EOF dummy_client -s $ctdbd_socket & pid=$! +wait_until 10 $CTDB process-exists "$pid" + ok "PID $pid exists" simple_test "$pid" -- 2.14.2