Diff options
Diffstat (limited to 'tests/t0003-cache.sh')
| -rwxr-xr-x | tests/t0003-cache.sh | 75 |
1 file changed, 75 insertions, 0 deletions
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 6a04411..c0e9f1d 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -858,6 +858,81 @@ test_expect_success 'a negative cache-scan-ttl never expires the list' ' test_grep ! "^repo.url=kept$" "cache5/$scanned_rc" ' +# Starts a request in the background whose stdin, stdout and stderr are pipes, +# and returns once the request is over, which is only when every process +# holding those pipes has let go, or fails after 30 seconds. The rescan child +# keeps fd 9, so the reader of that pipe, and with it the background job, ends +# only when the child does. +start_rescan_request() { + rm -f rescan.done + { + { + cat /dev/zero 2>/dev/null | + cgit_rc pipelistrc "url=" 2>&1 | + cat >rescan.out && + touch rescan.done + } 9>&1 >/dev/null | cat + } & + rescan_pid=$! + n=0 + while ! test -f rescan.done && test $n -lt 30 + do + sleep 1 + n=$((n + 1)) + done + test -f rescan.done +} + +# Writes the project list into the pipe the child is held on, which fails +# when no child is there to read it, and waits for the child to end. +finish_rescan() { + "$PERL_PATH" -e 'alarm 30; open(my $list, ">", shift) or die "$!\n"; print $list "one\n"' pipelist + finish_status=$? + wait "$rescan_pid" + return $finish_status +} + +rescan_behind_request() { + start_rescan_request + rescan_status=$? + finish_rescan && + return $rescan_status +} + +# An expired list is rebuilt by a child forked off the request, which answers +# from the stale list meanwhile. A web server reads the request's stdout until +# every holder is gone, so the child drops it, along with stdin and stderr. A +# project list that is a pipe holds the child until the test writes the list +# into it, after the request has ended. +test_expect_success PIPE,PERL_RUNS 'a background rescan lets the request finish' ' + mkrepo piped/one 1 && + echo one >pipelist && + { + echo "virtual-root=/" && + echo "cache-root=$PWD/cache10" && + echo "cache-size=64" && + echo "cache-index-ttl=0" && + echo "project-list=$PWD/pipelist" && + echo "scan-path=$PWD/piped" + } >pipelistrc && + rm -rf cache10 && mkdir cache10 && + cgit_ok pipelistrc "url=" >/dev/null && + list=$(ls cache10/rc-*) && + { + echo "repo.url=kept" && + echo "repo.path=$PWD/piped/one/.git" + } >>"$list" && + touch -t 200001010000 "$list" && + rm pipelist && + mkfifo pipelist && + rescan_behind_request && + test_grep ">kept</a>" rescan.out && + test_grep "</html>" rescan.out && + test_grep ! "^\[cgit\]" rescan.out && + test_grep "^repo.url=one$" "$list" && + test_grep ! "^repo.url=kept$" "$list" +' + # A repository the scan found without a description goes into the list # without one, so its pages do not describe themselves with the placeholder. test_expect_success 'a cached scan leaves the description placeholder out' ' |
