summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2017-10-25 12:04:49 +1100
committerAmitay Isaacs <amitay@samba.org>2017-10-26 09:35:25 +0200
commitd69899238bfe468cd3e915f6d66e279811301d66 (patch)
treebb5848e78783b0ae48888776c0cb4e5f8e5ddcfb /ctdb/tests
parent16389bed0773952ca563b7bf1fecc2a737587257 (diff)
downloadsamba-d69899238bfe468cd3e915f6d66e279811301d66.tar.gz
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 <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tests')
-rw-r--r--ctdb/tests/scripts/common.sh44
-rw-r--r--ctdb/tests/scripts/integration.bash44
2 files changed, 44 insertions, 44 deletions
diff --git a/ctdb/tests/scripts/common.sh b/ctdb/tests/scripts/common.sh
index 93db417e652..099eee11d9c 100644
--- a/ctdb/tests/scripts/common.sh
+++ b/ctdb/tests/scripts/common.sh
@@ -47,3 +47,47 @@ esac
if [ -d "$_test_bin_dir" ] ; then
PATH="${_test_bin_dir}:$PATH"
fi
+
+# 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 ea8a28072bc..b627c3e1162 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}|"