From 753b06af5d0e05811c93f202a36a216735a2f1a7 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:05:51 -0700 Subject: Tidy the cache test's helpers and outputs The header's last sentence named two of the many later subjects, so it goes too. The second request's stderr is still kept, for the lock tests that come next. --- tests/t0003-cache.sh | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 5cf0250..7e92b05 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -2,8 +2,6 @@ # Exercises the cache. The first three tests set cache-size to nothing, one # slot and the full table in turn, then count what the requests left behind. -# The rest cover a page longer than the output buffer and a key too long to -# be read back. test_description='Validate cache' . ./setup.sh @@ -78,29 +76,10 @@ test_expect_success 'set up a repo with a page larger than the output buffer' ' rm -rf cache2 && mkdir cache2 ' -# 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() { - n=0 - rm -f filter-running - CGIT_CONFIG="$PWD/lockrc" QUERY_STRING="url=bigpage/about/" cgit >first.out 2>first.err & - while ! test -f filter-running && test $n -lt 10 - do - sleep 1 - n=$((n + 1)) - done - CGIT_CONFIG="$PWD/lockrc" QUERY_STRING="url=bigpage/log/" cgit >second.out 2>second.err - wait -} - -bigpage_query() { - CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="$1" cgit -} - test_expect_success 'the first request fills the slot and the second replays it' ' - bigpage_query "url=bigpage/tree/big.txt" >big.first && + CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.first && test $(wc -c big.second && + CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.second && strip_headers big.first.body && strip_headers big.second.body && test_cmp big.first.body big.second.body @@ -125,7 +104,7 @@ test_expect_success 'an over-long cache key leaves no slot behind' ' rm -rf cache3 && mkdir cache3 && sed -e "s|^cache-root=.*|cache-root=$PWD/cache3|" bigrc >bigkeyrc && long=$(awk "BEGIN{s=\"\";for(i=0;i<6000;i++)s=s \"k\"; print s}") && - CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/&q=$long" cgit >key.out 2>key.err && + CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/&q=$long" cgit >key.out 2>/dev/null && grep "" key.out && test_dir_is_empty cache3 ' @@ -250,6 +229,21 @@ test_expect_success 'a failed final write still delivers the page' ' ! grep "called many times" flush.err ' +# 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() { + n=0 + rm -f filter-running + CGIT_CONFIG="$PWD/lockrc" QUERY_STRING="url=bigpage/about/" cgit >first.out 2>first.err & + while ! test -f filter-running && test $n -lt 10 + do + sleep 1 + n=$((n + 1)) + done + CGIT_CONFIG="$PWD/lockrc" QUERY_STRING="url=bigpage/log/" cgit >/dev/null 2>second.err + wait +} + # The fill writes the page into the lock file through stdout, and an exec # filter puts its own pipe on stdout while it runs. The slot lock has to # outlast that, or a second request on the slot rebuilds it under the first -- cgit