aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-03-29 23:30:17 -0400
committerJonathan Nieder <jrnieder@gmail.com>2011-03-29 23:18:27 -0500
commita892a2ddfefca2e25d595bb685c8853d023fde0a (patch)
tree6b227513b693c4ab9873f531016cca35eb0224db /t
parent9e113988d3d95f1595e2c33f704defeb2cbcc5d6 (diff)
downloadgit-a892a2ddfefca2e25d595bb685c8853d023fde0a.tar.gz
git-a892a2ddfefca2e25d595bb685c8853d023fde0a.tar.xz
tests: kill backgrounded processes more robustly
t0081 creates several background processes that write to a fifo and then go to sleep for a while (so the reader of the fifo does not see EOF). Each background process is made in a curly-braced block in the shell, and after we are done reading from the fifo, we use "kill $!" to kill it off. For a simple, single-command process, this works reliably and kills the child sleep process. But for more complex commands like "make_some_output && sleep", the results are less predictable. When executing under bash, we end up with a subshell that gets killed by the $! but leaves the sleep process still alive. This is bad not only for process hygeine (we are leaving random sleep processes to expire after a while), but also interacts badly with the "prove" command. When prove executes a test, it does not realize the test is done when it sees SIGCHLD, but rather waits until the test's stdout pipe is closed. The orphaned sleep process may keep that pipe open via test-lib's file descriptor 5, causing prove to hang for 100 seconds. The solution is to explicitly use a subshell and to exec the final sleep process, so that when we "kill $!" we get the process id of the sleep process. [jn: original patch by Jeff had some additional bits: 1. Wrap the "kill" in a test_when_finished, since we want to clean up the process whether the test succeeds or not. 2. The "kill" is part of our && chain for test success. It probably won't fail, but it can if the process has expired before we manage to kill it. So let's mark it as OK to fail. I'm postponing that for now.] Reported-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t0081-line-buffer.sh12
1 files changed, 6 insertions, 6 deletions
diff --git a/t/t0081-line-buffer.sh b/t/t0081-line-buffer.sh
index 1dbe1c9b0..5067d1e15 100755
--- a/t/t0081-line-buffer.sh
+++ b/t/t0081-line-buffer.sh
@@ -47,10 +47,10 @@ long_read_test () {
rm -f input &&
mkfifo input &&
{
- {
+ (
generate_tens_of_lines $tens_of_lines "$line" &&
- sleep 100
- } >input &
+ exec sleep 100
+ ) >input &
} &&
test-line-buffer input <<-EOF >output &&
binary $readsize
@@ -109,11 +109,11 @@ test_expect_success PIPE '1-byte read, no input available' '
rm -f input &&
mkfifo input &&
{
- {
+ (
printf "%s" a &&
printf "%s" b &&
- sleep 100
- } >input &
+ exec sleep 100
+ ) >input &
} &&
test-line-buffer input <<-\EOF >actual &&
binary 1