Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Test a lock won after its file became the slot
Diffstat (limited to 'tests/t0003-cache.sh')
| -rwxr-xr-x | tests/t0003-cache.sh | 30 |
1 file changed, 29 insertions, 1 deletion
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index ec88046..e07fcd0 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -231,7 +231,7 @@ test_expect_success 'a failed final write still delivers the page' ' # The second request lands while the first is inside its filter, which says # so through a marker file, since a fresh binary can take a moment to start. -overlap_requests() { +start_first_request() { n=0 rm -f filter-running cgit_rc lockrc "url=bigpage/about/" >first.out 2>first.err & @@ -240,6 +240,10 @@ overlap_requests() { sleep 1 n=$((n + 1)) done +} + +overlap_requests() { + start_first_request cgit_rc lockrc "url=bigpage/log/" >/dev/null 2>second.err wait } @@ -269,6 +273,30 @@ test_expect_success 'a slot stays locked while an exec filter runs' ' ! grep "Unable to lock" second.err ' +# A request that opens the lock file just before its holder renames it into +# place as the live slot goes on to lock the slot itself. strace holds the +# second request's flock back until the first has finished, and the check +# that the path still names the locked file turns that lock down, so the +# slot keeps the first request's key. strace needs ptrace and a version that +# can delay a call, which containers and older systems may not give. +test_lazy_prereq STRACE_DELAY ' + strace -o /dev/null -e inject=flock:delay_enter=1 true +' + +test_expect_success STRACE_DELAY 'a lock taken after the rename leaves the slot alone' ' + rm -rf cache3 && mkdir cache3 && + start_first_request && + strace -o /dev/null -e inject=flock:delay_enter=4000000 \ + -E CGIT_CONFIG="$PWD/lockrc" -E QUERY_STRING="url=bigpage/log/" \ + cgit >second.out 2>second.err && + wait && + grep "id=.about." first.out && + grep "</html>" second.out && + tr "\000" "\n" <"cache3/$(ls cache3)" | head -n 1 >slot.key && + grep "about" slot.key && + ! grep "log" slot.key +' + # An flock lasts until the last copy of its descriptor closes, so a filter # may hold the slot's lock file only as the stdout it writes the page to. A # stray copy would keep the slot locked for as long as the filter, or |
