diff options
Diffstat (limited to '')
-rwxr-xr-xtests/t0003-cache.sh79
1 file changed, 74 insertions, 5 deletions
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh
index 3e2a971..06cdd99 100755
--- a/tests/t0003-cache.sh
+++ b/tests/t0003-cache.sh
@@ -79,6 +79,21 @@ 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
}
@@ -96,11 +111,7 @@ test_expect_success 'the cached body matches one generated with the cache off' '
sed -e "s/^cache-size=64$/cache-size=0/" bigrc >bignocache &&
CGIT_CONFIG="$PWD/bignocache" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.nocache &&
strip_headers <big.nocache >big.nocache.body &&
- # The footer carries the time the page was generated, which the two runs
- # cannot agree on.
- sed -e "s/generated by .*//" big.nocache.body >big.nocache.timeless &&
- sed -e "s/generated by .*//" big.second.body >big.cached.timeless &&
- test_cmp big.nocache.timeless big.cached.timeless
+ test_cmp big.nocache.body big.second.body
'
test_expect_success 'the page ends where it should, so nothing was dropped' '
@@ -212,4 +223,62 @@ test_expect_success 'an expired slot is dropped when its refill is too large' '
test_line_count = 0 refill.slots
'
+# The summary page keeps a ttl of its own, while every other page that follows
+# a branch rather than a pinned id takes cache-dynamic-ttl, whether or not its
+# url names the branch.
+test_expect_success 'pages following a branch take the dynamic ttl' '
+ rm -rf cache3 && mkdir cache3 &&
+ {
+ echo "cache-dynamic-ttl=0" &&
+ cat bigkeyrc
+ } >dynamicrc &&
+ CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/log/" cgit >/dev/null &&
+ CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/log/&h=master" cgit >/dev/null &&
+ ls cache3 >dynamic.slots &&
+ test_line_count = 0 dynamic.slots &&
+ CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/" cgit >/dev/null &&
+ CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/summary/" cgit >/dev/null &&
+ ls cache3 >summary.slots &&
+ test_line_count = 2 summary.slots
+'
+
+# A write into the lock file that fails on the page's last flush has to end
+# as one that fails mid page does, with the fill abandoned and the page
+# delivered from the lock file, rather than in a blank response. The limit
+# is on files alone, so the page goes to the visitor through a pipe.
+test_expect_success 'a failed final write still delivers the page' '
+ rm -rf cache3 && mkdir cache3 &&
+ (
+ trap "" XFSZ &&
+ ulimit -f 2 &&
+ CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" cgit 2>flush.err
+ ) | cat >flush.out &&
+ grep "^Status: 200" flush.out &&
+ grep "</html>" flush.out &&
+ ! grep "called many times" flush.err
+'
+
+# 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
+# and the first visitor gets the two pages spliced together.
+test_expect_success 'a slot stays locked while an exec filter runs' '
+ rm -rf cache3 && mkdir cache3 &&
+ write_script slow-filter.sh <<-EOF &&
+ touch "$PWD/filter-running"
+ sleep 3
+ cat
+ EOF
+ {
+ echo "cache-size=1" &&
+ sed "/^cache-size=/d" bigkeyrc &&
+ echo "repo.readme=:file-1" &&
+ echo "repo.about-filter=exec:$PWD/slow-filter.sh"
+ } >lockrc &&
+ overlap_requests &&
+ test $(grep -c "^Status:" first.out) = 1 &&
+ grep "id=.about." first.out &&
+ ! grep "Unable to publish" first.err
+'
+
test_done