Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Lock the cached repolist with flock
The slot lock has to be an flock, since an exec filter drops a record lock when it closes the stdout a fill writes through. The scan only got by with fcntl because nothing reopens its file while it runs. One kind of lock lets the two share their code, and on Linux, where the kinds never see each other, an flock on the scan's file now holds a scan off like any other.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/t0003-cache.sh38
1 file changed, 38 insertions, 0 deletions
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh
index 945ac63..8b3f2f9 100755
--- a/tests/t0003-cache.sh
+++ b/tests/t0003-cache.sh
@@ -294,4 +294,42 @@ test_expect_success PERL 'a filter holds the lock file only as its stdout' '
grep -F "lock file on fd 1." fd.out
'
+# A scan is cached in a file named after the hash of its path, so a first
+# scan finds out what that name is. The index page is left uncached, which
+# makes each request read the list afresh.
+test_expect_success 'set up a cached scan of two repositories' '
+ mkrepo scanned/one 1 &&
+ mkrepo scanned/two 1 &&
+ {
+ echo "virtual-root=/" &&
+ echo "cache-root=$PWD/cache5" &&
+ echo "cache-size=64" &&
+ echo "cache-index-ttl=0" &&
+ echo "scan-path=$PWD/scanned"
+ } >scanrc &&
+ rm -rf cache5 && mkdir cache5 &&
+ CGIT_CONFIG="$PWD/scanrc" QUERY_STRING="url=" cgit >/dev/null &&
+ scanned_rc=$(ls cache5) &&
+ test_path_is_file "cache5/$scanned_rc"
+'
+
+# A request that finds the scan's lock held and has no list to go on scans
+# 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
+ rm "cache5/$scanned_rc" &&
+ CGIT_CONFIG="$PWD/scanrc" QUERY_STRING="url=" \
+ ./hold-lock "cache5/$scanned_rc.lock" cgit >held.out 2>held.err &&
+ grep ">one</a>" held.out &&
+ grep ">two</a>" held.out &&
+ test_path_is_missing "cache5/$scanned_rc" &&
+ test_must_be_empty held.err
+'
+
test_done