summaryrefslogtreecommitdiff
path: root/tests/init.cfg
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-07-05 08:53:10 +0100
committerPádraig Brady <P@draigBrady.com>2010-07-05 15:06:07 +0100
commit09fcf494a10c4b1ad2b037d093f571e7462e08c4 (patch)
treeb37ab28311bb36e20c3f18f09531196dd70381b1 /tests/init.cfg
parent1d95457b3ecc57df4cd67175abd093b84e29372b (diff)
downloadcoreutils-09fcf494a10c4b1ad2b037d093f571e7462e08c4.tar.xz
tests: make tests requiring a delay to pass, more robust
* tests/init.cfg: Introduce a retry_delay_() function to repeatedly call a test function that requires a delay. This delay can now be shorter for the common case on fast systems, but will double until a configurable limit it reached before failing on slower systems. * tests/dd/reblock: Use retry_delay_. * tests/misc/cat-buf: Likewise. * tests/misc/stdbuf: Likewise. * tests/tail-2/F-vs-rename: Likewise. * tests/tail-2/flush-initial: Likewise. * tests/tail-2/tail-n0f: Likewise. * tests/tail-2/wait: Likewise. * test/dd/misc: Comment that delay is needed to trigger failure.
Diffstat (limited to 'tests/init.cfg')
-rw-r--r--tests/init.cfg27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/init.cfg b/tests/init.cfg
index aecdd5a2c..232cb9bae 100644
--- a/tests/init.cfg
+++ b/tests/init.cfg
@@ -357,4 +357,31 @@ working_umask_or_skip_()
esac
}
+# Continually retry a function requiring a sufficient delay to _pass_
+# Example: retry_delay dd_reblock_1 .1 6
+# This example will call the dd_reblock_1 function with
+# an initial delay of .1 second and call it at most 6 times
+# with a max delay of 3.2s (doubled each time), or a total of 6.3s
+# Note ensure you do _not_ quote the parameter to GNU sleep in
+# your function, as it may contain separate values that `sleep`
+# needs to accumulate.
+retry_delay_()
+{
+ local test_func=$1
+ local init_delay=$2
+ local max_n_tries=$3
+
+ local attempt=1
+ local num_sleeps=$attempt
+ local time_fail
+ while test $attempt -le $max_n_tries; do
+ local delay=$($AWK -v n=$num_sleeps -v s="$init_delay" \
+ 'BEGIN { for (i=0;i<n;i++) t = s" "t; print t }')
+ "$test_func" "$delay" && { time_fail=0; break; } || time_fail=1
+ attempt=$(expr $attempt + 1)
+ num_sleeps=$(expr $num_sleeps '*' 2)
+ done
+ test "$time_fail" = 0
+}
+
sanitize_path_