Diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0003-cache.sh | 34 |
1 file changed, 28 insertions, 6 deletions
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 232f6ff..a65b3ce 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -20,6 +20,17 @@ request_all_pages() { done } +# Runs a command while holding the flock on the file named first, as another +# request at work on the same lock would. +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); + EOF +} + test_expect_success 'a cache-size of 0 leaves no slot behind' ' rm -f cache/* && sed "s/^cache-size=.*/cache-size=0/" cgitrc >size0rc && @@ -446,6 +457,22 @@ test_expect_success SANITY 'a refresh that cannot lock serves the expired slot a grep "Unable to open .*\.lock: Permission denied" stale.err ' +# A refresh that finds the lock held is another request already at work on +# the slot, so the expired copy is served and nothing is logged. +test_expect_success PERL 'a refresh finding the lock held serves the expired slot quietly' ' + write_hold_lock && + rm -rf cache3 && mkdir cache3 && + cgit_ok bigkeyrc "url=bigpage/" >/dev/null && + slot=$(ls cache3) && + echo "the expired copy" >>"cache3/$slot" && + touch -t 200001010000 "cache3/$slot" && + CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" \ + ./hold-lock "cache3/$slot.lock" cgit >held.out 2>held.err && + test_grep "^Status: 200" held.out && + test_grep "the expired copy" held.out && + test_must_be_empty held.err +' + # A lock file that cannot take the key goes with its lock, rather than # staying behind locked while the page renders uncached. The limit is on # files, so the log and cgit's exit status go through the pipe as well. @@ -485,12 +512,7 @@ test_expect_success 'set up a cached scan of two repositories' ' # in its own process, leaving the file to the holder. That is only another # request at work and no cause for a line in the log. test_expect_success PERL 'a scan finding its lock held runs uncached' ' - 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); - EOF + write_hold_lock && rm "cache5/$scanned_rc" && CGIT_CONFIG="$PWD/scanrc" QUERY_STRING="url=" \ ./hold-lock "cache5/$scanned_rc.lock" cgit >held.out 2>held.err && |
