summaryrefslogtreecommitdiff
path: root/tests/tail-2/inotify-rotate
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-06-30 17:10:07 +0200
committerJim Meyering <meyering@redhat.com>2010-06-30 18:12:12 +0200
commit7336920dd07478b7bdae05ec599da4e2e66a94ff (patch)
tree12091115128e17a39c3507f7c495169ae0eb9e58 /tests/tail-2/inotify-rotate
parentb062bbd94712c9a761ee42b9ac267651b334f836 (diff)
downloadcoreutils-7336920dd07478b7bdae05ec599da4e2e66a94ff.tar.xz
tests: fail rather than infloop in tail's inotify-rotate test
* tests/tail-2/inotify-rotate: Switch to new init.sh-based framework. (grep_timeout): New function. Use it in place of open-coded loops that might infloop. This was prompted by my encountering an inexplicable, and so far unreproducible, infloop in the code that was waiting for "b" to appear in "out".
Diffstat (limited to 'tests/tail-2/inotify-rotate')
-rwxr-xr-xtests/tail-2/inotify-rotate22
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/tail-2/inotify-rotate b/tests/tail-2/inotify-rotate
index 51cd81bb1..9a3933e83 100755
--- a/tests/tail-2/inotify-rotate
+++ b/tests/tail-2/inotify-rotate
@@ -21,9 +21,21 @@ if test "$VERBOSE" = yes; then
tail --version
fi
-. $srcdir/test-lib.sh
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
expensive_
+# Wait up to 10 seconds for grep REGEXP FILE to succeed.
+# Usage: grep_timeout REGEXP FILE
+grep_timeout()
+{
+ local j
+ for j in $(seq 100); do
+ grep $1 $2 > /dev/null && return 0
+ sleep 0.1
+ done
+ return 1
+}
+
# For details, see
# http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html
@@ -37,17 +49,15 @@ for i in $(seq 50); do
sleep .1
echo b > k;
# wait for b to appear in out
+ grep_timeout b out || fail_ failed to find b in out
while :; do grep b out > /dev/null && break; done
mv x k
# wait for tail to detect the rename
- while :; do grep tail: out > /dev/null && break; done
+ grep_timeout tail: out || fail_ failed to detect rename
echo ok >> k
found=0
# wait up to 10 seconds for "ok" to appear in out
- for j in $(seq 100); do
- grep ok out > /dev/null && { found=1; break; }
- sleep 0.1
- done
+ grep_timeout ok out && found=1
kill $pid
test $found = 0 && { fail=1; cat out; break; }
done