#!/bin/sh test_description='Validate cache' . ./setup.sh test_expect_success 'verify cache-size=0' ' rm -f cache/* && sed -e "s/cache-size=1021$/cache-size=0/" cgitrc >cgitrc.tmp && mv -f cgitrc.tmp cgitrc && cgit_url "" && cgit_url "foo" && cgit_url "foo/refs" && cgit_url "foo/tree" && cgit_url "foo/log" && cgit_url "foo/diff" && cgit_url "foo/patch" && cgit_url "bar" && cgit_url "bar/refs" && cgit_url "bar/tree" && cgit_url "bar/log" && cgit_url "bar/diff" && cgit_url "bar/patch" && ls cache >output && test_line_count = 0 output ' test_expect_success 'verify cache-size=1' ' rm -f cache/* && sed -e "s/cache-size=0$/cache-size=1/" cgitrc >cgitrc.tmp && mv -f cgitrc.tmp cgitrc && cgit_url "" && cgit_url "foo" && cgit_url "foo/refs" && cgit_url "foo/tree" && cgit_url "foo/log" && cgit_url "foo/diff" && cgit_url "foo/patch" && cgit_url "bar" && cgit_url "bar/refs" && cgit_url "bar/tree" && cgit_url "bar/log" && cgit_url "bar/diff" && cgit_url "bar/patch" && ls cache >output && test_line_count = 1 output ' test_expect_success 'verify cache-size=1021' ' rm -f cache/* && sed -e "s/cache-size=1$/cache-size=1021/" cgitrc >cgitrc.tmp && mv -f cgitrc.tmp cgitrc && cgit_url "" && cgit_url "foo" && cgit_url "foo/refs" && cgit_url "foo/tree" && cgit_url "foo/log" && cgit_url "foo/diff" && cgit_url "foo/patch" && cgit_url "bar" && cgit_url "bar/refs" && cgit_url "bar/tree" && cgit_url "bar/log" && cgit_url "bar/diff" && cgit_url "bar/patch" && ls cache >output && test_line_count = 13 output && cgit_url "foo/ls_cache" >output.full && strip_headers 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. test_expect_success 'set up a repo with a page larger than the output buffer' ' mkrepo repos/bigpage 1 && ( cd repos/bigpage && awk "BEGIN{for(i=0;i<20000;i++) print \"line \" i \" of the big file\"}" >big.txt && git add big.txt && git commit -m "add big.txt" ) && { echo "virtual-root=/" && echo "cache-root=$PWD/cache2" && echo "cache-size=64" && echo "enable-tree-linenumbers=1" && echo "repo.url=bigpage" && echo "repo.path=$PWD/repos/bigpage/.git" } >bigrc && rm -rf cache2 && mkdir cache2 ' bigq() { 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 && test $(wc -c big.second && strip_headers big.first.body && strip_headers big.second.body && test_cmp big.first.body big.second.body ' 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.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 ' test_expect_success 'the page ends where it should, so nothing was dropped' ' tail -c 200 big.second.body | grep "" ' test_done