diff options
author | Pádraig Brady <P@draigBrady.com> | 2010-07-05 08:53:10 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2010-07-05 15:06:07 +0100 |
commit | 09fcf494a10c4b1ad2b037d093f571e7462e08c4 (patch) | |
tree | b37ab28311bb36e20c3f18f09531196dd70381b1 /tests/tail-2 | |
parent | 1d95457b3ecc57df4cd67175abd093b84e29372b (diff) | |
download | coreutils-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/tail-2')
-rwxr-xr-x | tests/tail-2/F-vs-rename | 50 | ||||
-rwxr-xr-x | tests/tail-2/flush-initial | 17 | ||||
-rwxr-xr-x | tests/tail-2/tail-n0f | 18 | ||||
-rwxr-xr-x | tests/tail-2/wait | 35 |
4 files changed, 67 insertions, 53 deletions
diff --git a/tests/tail-2/F-vs-rename b/tests/tail-2/F-vs-rename index 38a1b3f40..74db80137 100755 --- a/tests/tail-2/F-vs-rename +++ b/tests/tail-2/F-vs-rename @@ -42,36 +42,36 @@ mv a b || fail=1 until grep inaccessible out >/dev/null 2>&1; do :; done echo x > a -# Wait up to 4s for this to appear in the output: +# Wait up to 6.3s for this to appear in the output: # "tail: `...' has appeared; following end of new file" -found=false -for i in $(seq 20); do - grep 'has appeared;' out > /dev/null && { found=true; break; } - sleep .2 -done -$found || { echo "$0: a: unexpected delay?"; cat out; fail=1; } +tail_f_vs_rename_1() +{ + local delay="$1" + grep 'has appeared;' out > /dev/null || + { sleep $delay; return 1; } +} +retry_delay_ tail_f_vs_rename_1 .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } echo y >> b -# Wait up to 4s for "y" to appear in the output: -found=false -for i in $(seq 20); do - case $(tr '\n' @ < out) in - *'@@==> b <==@y@') found=true; break 2;; - esac - sleep .2 -done -$found || { echo "$0: b: unexpected delay?"; cat out; fail=1; } +# Wait up to 6.3s for "y" to appear in the output: +tail_f_vs_rename_2() { + local delay="$1" + tr '\n' @ < out | grep '@@==> b <==@y@$' > /dev/null || + { sleep $delay; return 1; } +} +retry_delay_ tail_f_vs_rename_2 .1 7 || + { echo "$0: b: unexpected delay?"; cat out; fail=1; } echo z >> a -# Wait up to 4s for "z" to appear in the output: -found=false -for i in $(seq 20); do - case $(tr '\n' @ < out) in - *'@@==> a <==@z@') found=true; break 2;; - esac - sleep .2 -done -$found || { echo "$0: b: unexpected delay?"; cat out; fail=1; } +# Wait up to 6.3s for "z" to appear in the output: +tail_f_vs_rename_3() { + local delay="$1" + tr '\n' @ < out | grep '@@==> a <==@z@$' > /dev/null || + { sleep $delay; return 1; } +} +retry_delay_ tail_f_vs_rename_3 .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } kill -HUP $pid diff --git a/tests/tail-2/flush-initial b/tests/tail-2/flush-initial index cf5438011..98de2e1f5 100755 --- a/tests/tail-2/flush-initial +++ b/tests/tail-2/flush-initial @@ -29,14 +29,15 @@ echo line > in || fail=1 tail -f in > out & tail_pid=$! -# Wait for 1 second for the file to be flushed. -for i in $(seq 10); do - test -s out && break - echo sleep .1s - sleep .1 -done - -test -s out || fail=1 +# Wait for 1.5s for the file to be flushed. +tail_flush() +{ + local delay="$1" + + test -s out || + { sleep "$delay"; return 1; } +} +retry_delay_ tail_flush .1 5 || fail=1 kill $tail_pid diff --git a/tests/tail-2/tail-n0f b/tests/tail-2/tail-n0f index 0ff3a3d01..6a9b59c37 100755 --- a/tests/tail-2/tail-n0f +++ b/tests/tail-2/tail-n0f @@ -39,12 +39,18 @@ for inotify in ---disable-inotify ''; do for c_or_n in c n; do tail --sleep=4 -${c_or_n} 0 -f $inotify $file & pid=$! - sleep .5 - state=$(get_process_status_ $pid) - case $state in - S*) ;; - *) echo $0: process in unexpected state: $state 1>&2; fail=1 ;; - esac + tail_sleeping() + { + local delay="$1"; sleep $delay + state=$(get_process_status_ $pid) + case $state in + S*) ;; + *) return 1;; + esac + } + # Wait up to 1.5s for tail to sleep + retry_delay_ tail_sleeping .1 4 || + { echo $0: process in unexpected state: $state >&2; fail=1; } kill $pid done done diff --git a/tests/tail-2/wait b/tests/tail-2/wait index 5c9eff0a2..332cfcc09 100755 --- a/tests/tail-2/wait +++ b/tests/tail-2/wait @@ -25,7 +25,6 @@ fi . $srcdir/test-lib.sh touch here || framework_failure -touch k || framework_failure { touch unreadable && chmod a-r unreadable; } || framework_failure @@ -59,19 +58,27 @@ for inotify in ---disable-inotify ''; do test -s tail.err && fail=1 :>tail.err - - tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out & - pid=$! - sleep .5 - mv k l - sleep .5 - touch k - mv k l - sleep .5 - echo NO >> l - sleep .5 - kill $pid - test -s tail.out && fail=1 + tail_F() + { + local delay="$1" + + touch k || framework_failure + tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out & + pid=$! + sleep $delay + mv k l + sleep $delay + touch k + mv k l + sleep $delay + echo NO >> l + sleep $delay + kill $pid + rm -f k l + + test ! -s tail.out + } + retry_delay_ tail_F .1 4 || fail=1 done Exit $fail |