Diff options
| -rwxr-xr-x | tests/t0003-cache.sh | 15 |
1 file changed, 12 insertions, 3 deletions
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index b1b0a2b..6a04411 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -30,13 +30,21 @@ test_lazy_prereq PERL_RUNS ' ' # Runs a command while holding the flock on the file named first, as another -# request at work on the same lock would. +# request at work on the same lock would. The command has to start inside the +# hold, which cgit_rc cannot do, so the alarm cgit_rc would set is set here, +# and a cgit that waits on the lock fails its test rather than stalling it. write_hold_lock() { write_script hold-lock "$PERL_PATH" <<-\EOF use Fcntl qw(:flock); open(my $lock, ">>", shift) or die "$!\n"; flock($lock, LOCK_EX | LOCK_NB) or die "$!\n"; - exit(system(@ARGV) ? 1 : 0); + defined(my $pid = fork) or die "$!\n"; + if (!$pid) { + alarm 60; + exec @ARGV or die "$ARGV[0]: $!\n"; + } + waitpid($pid, 0); + exit($? ? 1 : 0); EOF } @@ -498,7 +506,8 @@ test_lazy_prereq STRACE_DELAY ' ' # Returns once the trace shows the second request has opened the lock file, -# which the first request still holds. +# which the first request still holds. strace has to start cgit itself, so +# the request is set up here rather than by cgit_rc. start_traced_request() { rm -f second.trace strace -o second.trace -e trace=%file,flock \ |
