Subject: | sh-c test randomly fails |
Date: | Mon, 25 Jul 2011 11:47:23 +0100 |
To: | bug-Proc-Simple [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
Proc::Simple's sh-c.t test for support for running shell commands
is faulty, suffering from a race condition. Specifically: after
SIGTERMing the subordinate process group, it waits for its immediate
child to terminate, then expects that the flag file has been removed.
However, its immediate child is the shell process, whereas the flag file
is removed by the SIGTERM handler of its grandchild, which it doesn't
wait for. So the test may pass or fail, randomly, depending on how soon
the grandchild's SIGTERM handler runs relative to when the immediate
chald terminates and the parent notices.
The chance of this false failure can be massively reduced by adding a
"sleep 1" immediately before the final test for whether the flag file
was unlinked. Alternatively, you could use another mechanism (second
flag file, or kill(0,$pid) with the PID determined by other means) to
wait until the grandchild has terminated (one way or another) before
checking that its SIGTERM handler was run.
-zefram