]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: simplify and fix a race in 2 tail --follow tests
authorPádraig Brady <P@draigBrady.com>
Wed, 2 Sep 2009 23:39:17 +0000 (00:39 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 3 Sep 2009 09:08:06 +0000 (10:08 +0100)
* tests/tail-2/pid: Use the timeout command to determine process
longevity, rather than querying /proc/$pid/status.
The latter was racy in any case when inotify is used, as then
tail wakes up periodically even for unchanging files therefore
causing the check for "S (sleeping)" state to fail intermittently.
* tests/tail-2/wait: Likewise.

tests/tail-2/pid
tests/tail-2/wait

index 86e3d60c0839ce584d3eb49b28576e5ac23b325e..a797666fec5e00ce8fba2864054e116ddcdbdcaa 100755 (executable)
@@ -23,48 +23,21 @@ fi
 
 . $srcdir/test-lib.sh
 
-require_proc_pid_status_
-
 touch here || framework_failure
 
-
 fail=0
 
-# Use tail itself to create a background process.
-
+# Use tail itself to create a background process to monitor.
 tail -f here &
 bg_pid=$!
 
-tail -s0.1 -f here --pid=$bg_pid &
-
-pid=$!
-
-sleep 0.5
-
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo "$0: process dead? (state=$state)" 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+# Ensure that tail --pid=PID does not exit when PID is alive.
+timeout 1 tail -s.1 -f here --pid=$bg_pid
+test $? = 124 || fail=1
 
+# Cleanup background process
 kill $bg_pid
 
-sleep 0.5
-
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) echo $0: process still active 1>&2; fail=1 ;;
-    *) ;;
-  esac
-  kill $pid
-fi
-
 # Ensure that tail --pid=PID exits successfully when PID is dead.
 # Use an unlikely-to-be-live PID
 getlimits_
index a902b54bb02b5df6a3c2f8920944fae9c124eb8d..eb04ac2307cc9c7e7259215fa6c81e0b5869e36b 100755 (executable)
@@ -24,97 +24,32 @@ fi
 
 . $srcdir/test-lib.sh
 
-require_proc_pid_status_
-
 touch here || framework_failure
 touch k || framework_failure
-(touch unreadable && chmod a-r unreadable) || framework_failure
+{ touch unreadable && chmod a-r unreadable; } || framework_failure
+cat unreadable && framework_failure
 
 fail=0
 
-tail -s0.1 -f not_here &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) echo $0: process still active 1>&2; fail=1 ;;
-    *) ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -f not_here
+test $? = 124 && fail=1
 
-# Check if the file is really not accessible before use it.
-if ! cat unreadable; then
-    tail -s0.1 -f unreadable &
-    pid=$!
-    sleep .5
-    state=$(get_process_status_ $pid)
-
-    if test -n "$state"; then
-        case $state in
-            S*) echo $0: process still active 1>&2; fail=1 ;;
-            *) ;;
-        esac
-        kill $pid
-    fi
-fi
-
-(tail -s0.1 -f here 2>tail.err) &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *)  echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -f unreadable
+test $? = 124 && fail=1
 
+timeout 1 tail -s0.1 -f here 2>tail.err
+test $? = 124 || fail=1
 
 # `tail -F' must wait in any case.
 
-(tail -s0.1 -F here 2>>tail.err) &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -F here 2>>tail.err
+test $? = 124 || fail=1
 
-tail -s0.1 -F unreadable &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -F unreadable
+test $? = 124 || fail=1
 
-tail -s0.1 -F not_here &
-pid=$!
-sleep .5
-state=$(get_process_status_ $pid)
-
-if test -n "$state"; then
-  case $state in
-    S*) ;;
-    *) echo $0: process died 1>&2; fail=1 ;;
-  esac
-  kill $pid
-fi
+timeout 1 tail -s0.1 -F not_here
+test $? = 124 || fail=1
 
 test -s tail.err && fail=1