ctdb-tests: Allow wait_until() to be used in unit tests
authorMartin Schwenke <martin@meltin.net>
Wed, 25 Oct 2017 01:04:49 +0000 (12:04 +1100)
committerKarolin Seeger <kseeger@samba.org>
Wed, 1 Nov 2017 09:49:25 +0000 (10:49 +0100)
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>
(cherry picked from commit d69899238bfe468cd3e915f6d66e279811301d66)

ctdb/tests/scripts/common.sh
ctdb/tests/scripts/integration.bash

index 287fb71fd1d76e259e123d6a58117f4931691234..e20b6d0ee7e944edf1afee7e04bfee59ec7c8764 100644 (file)
@@ -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
+}
index 4f1227f4393f340cc84c8c56205d5b6395128e4b..d72c471e41a4114f8c3b2faa9c6e0cf8d5ae138e 100644 (file)
@@ -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}|"