diff options
context:
space:
mode:
Diffstat (limited to 'tests/t0020-validate-cache.sh')
-rwxr-xr-xtests/t0020-validate-cache.sh43
1 file changed, 26 insertions, 17 deletions
diff --git a/tests/t0020-validate-cache.sh b/tests/t0020-validate-cache.sh
index 510e51c..0cf7433 100755
--- a/tests/t0020-validate-cache.sh
+++ b/tests/t0020-validate-cache.sh
@@ -1,5 +1,12 @@
#!/bin/sh
+# Exercises the cache, which keeps a rendered page in a slot on disk and
+# replays it for the next request that asks for the same thing. The first three
+# tests set cache-size to nothing, to one slot and to the full table in turn,
+# then count what the requests left behind. The rest cover the two ways a slot
+# can come out wrong, a page longer than the output buffer and a key too long
+# to be read back.
+
test_description='Validate cache'
. ./setup.sh
@@ -70,15 +77,14 @@ test_expect_success 'verify cache-size=1021' '
cgit_url "foo/ls_cache" >output.full &&
strip_headers <output.full >output &&
test_line_count = 13 output &&
- # Check that ls_cache output is cached correctly
cgit_url "foo/ls_cache" >output.second &&
test_cmp output.full output.second
'
-# --- A cached page must hold everything the uncached one produced -----------
-# Page output is buffered, so the slot is only complete if the buffer is
-# emptied before the generated content is measured. The blob here is larger
-# than one buffer, so a missing flush would truncate the cached copy.
+# Page output is buffered, so a slot only holds the whole page if the buffer is
+# emptied before the size of what was generated is taken. The blob set up here
+# is larger than one buffer, so a missing flush would leave the cached copy cut
+# short.
test_expect_success 'set up a repo with a page larger than the output buffer' '
mkrepo repos/bigpage 1 &&
(
@@ -98,12 +104,15 @@ test_expect_success 'set up a repo with a page larger than the output buffer' '
rm -rf cache2 && mkdir cache2
'
-bigq() { CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="$1" cgit; }
+bigpage_query()
+{
+ CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="$1" cgit
+}
test_expect_success 'the first request fills the slot and the second replays it' '
- bigq "url=bigpage/tree/big.txt" >big.first &&
+ bigpage_query "url=bigpage/tree/big.txt" >big.first &&
test $(wc -c <big.first) -gt 65536 &&
- bigq "url=bigpage/tree/big.txt" >big.second &&
+ bigpage_query "url=bigpage/tree/big.txt" >big.second &&
strip_headers <big.first >big.first.body &&
strip_headers <big.second >big.second.body &&
test_cmp big.first.body big.second.body
@@ -113,21 +122,21 @@ 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 differs
- # between the two runs by construction.
- sed -e "s/generated by .*//" big.nocache.body >big.a &&
- sed -e "s/generated by .*//" big.second.body >big.b &&
- test_cmp big.a big.b
+ # 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_expect_success 'the page ends where it should, so nothing was dropped' '
tail -c 200 big.second.body | grep "</html>"
'
-# --- A key too long to read back must not claim a slot ----------------------
-# A slot stores its key ahead of the content and only the first few kilobytes
-# are read back, so a longer key could never match. Such a request used to
-# write a slot on every visit that no later request could ever use.
+# A slot stores its key ahead of the content and only the first few kilobytes of
+# it are read back, so a key longer than that could never match. A request
+# carrying one used to leave a slot behind on every visit that nothing could
+# ever go on to use.
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 &&