>From de893d537dab5ab1ed2f61ee81c18603b52784d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Thu, 13 Oct 2011 14:58:58 +0100 Subject: [PATCH] tests: fix a race in timeout-group This could cause a false failure, or even an infinite loop in rare circumstances. * tests/misc/timeout-group: Increase the timeouts passed to the timeout command, so that they're effectively not used. Instead the command termination is triggered by the kill commands when everything is in the correct state. Reported by Bernhard Voelker. --- tests/misc/timeout-group | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/misc/timeout-group b/tests/misc/timeout-group index fedd53a..1ad2a87 100755 --- a/tests/misc/timeout-group +++ b/tests/misc/timeout-group @@ -40,15 +40,24 @@ chmod a+x timeout.cmd cat > group.sh <<\EOF #!/bin/sh -timeout --foreground 5 ./timeout.cmd 10& +timeout --foreground 25 ./timeout.cmd 20& wait EOF chmod a+x group.sh +check_timeout_cmd_running() +{ + local delay="$1" + test -e timeout.running || + { sleep $delay; return 1; } +} + + # Start above script in its own group. # We could use timeout for this, but that assumes an implementation. setsid ./group.sh & -until test -e timeout.running; do sleep .1; done +# Wait 6.3s for timeout.cmd to start +retry_delay_ check_timeout_cmd_running .1 6 || fail=1 # Simulate a Ctrl-C to the group to test timely exit # Note dash doesn't support signalling groups (a leading -) env kill -INT -- -$! @@ -66,9 +75,10 @@ rm -f int.received timeout.running # Note the first timeout must send a signal that # the second is handling for it to be propagated to the command. # SIGINT, SIGTERM, SIGALRM etc. are implicit. -timeout -sALRM 2 timeout -sINT 10 ./timeout.cmd 5& -until test -e timeout.running; do sleep .1; done -kill -ALRM $! +timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20& +# Wait 6.3s for timeout.cmd to start +retry_delay_ check_timeout_cmd_running .1 6 || fail=1 +kill -ALRM $! # trigger the alarm of the first timeout command wait test -e int.received || fail=1 -- 1.7.6