Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Prove one cache slot keeps its pages apart
The one-slot test threw every response away, so a slot that stopped
comparing keys and served whatever page it held still left one file
and passed. The collision MANUAL promises to log was never checked
either. The size tests also rewrote the shared cgitrc in place, and
the listing replay held only while the dynamic ttl did.
Diffstat (limited to 'tests/t0003-cache.sh')
| -rwxr-xr-x | tests/t0003-cache.sh | 59 |
1 file changed, 38 insertions, 21 deletions
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index 02622b5..5e8245b 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -6,50 +6,67 @@ test_description='Validate cache' . ./setup.sh -# The three counting tests below visit the same pages, the index plus six -# pages in each of two repositories, so the counts they expect stay tied to -# this one list of thirteen requests. +# The counting tests below visit the same pages, the index plus six pages in +# each of two repositories, so the counts they expect stay tied to this one +# list of thirteen requests. request_all_pages() { - cgit_url "" && + cgit_ok "$1" "url=" >/dev/null && for repo in foo bar do for page in "" /refs /tree /log /diff /patch do - cgit_url "$repo$page" || return 1 + cgit_ok "$1" "url=$repo$page" >/dev/null || return 1 done done } -set_cache_size() { - sed -e "s/^cache-size=.*$/cache-size=$1/" cgitrc >cgitrc.tmp && - mv -f cgitrc.tmp cgitrc -} - -test_expect_success 'verify cache-size=0' ' +test_expect_success 'a cache-size of 0 leaves no slot behind' ' rm -f cache/* && - set_cache_size 0 && - request_all_pages && + sed "s/^cache-size=.*/cache-size=0/" cgitrc >size0rc && + request_all_pages size0rc && test_dir_is_empty cache ' -test_expect_success 'verify cache-size=1' ' +# With one slot every request lands on the same file, so the key it holds is +# all that keeps one page from being served for another. +test_expect_success 'one slot serves each request its own page' ' rm -f cache/* && - set_cache_size 1 && - request_all_pages && + sed "s/^cache-size=.*/cache-size=1/" cgitrc >size1rc && + cgit_ok size1rc "url=foo/log/" >/dev/null && + cgit_rc size1rc "url=bar/refs/" >refs.out 2>refs.err && + test_grep "^Status: 200" refs.out && + test_grep "data-page=.refs. data-repo=.bar." refs.out && + test_grep "<table class=.list refs." refs.out && + test_grep ! "data-repo=.foo." refs.out && + test_grep "holds a different key, consider a larger cache-size" refs.err && + cgit_rc size1rc "url=foo/log/" >log.out 2>log.err && + test_grep "data-page=.log. data-repo=.foo." log.out && + test_grep "<table class=.list log." log.out && + test_grep ! "data-repo=.bar." log.out && + test_grep "holds a different key, consider a larger cache-size" log.err && ls cache >output && test_line_count = 1 output ' -test_expect_success 'verify cache-size=1021' ' +# The listing is a page like any other and takes a slot of its own, so a +# fresh render of it would list fourteen slots. Thirteen on the second +# request shows the first was replayed, which a dynamic ttl that never +# expires keeps true however slow the run. +test_expect_success 'a full table gives each request a slot of its own' ' rm -f cache/* && - set_cache_size 1021 && - request_all_pages && + { + echo "cache-dynamic-ttl=-1" && + sed "s/^cache-size=.*/cache-size=1021/" cgitrc + } >size1021rc && + request_all_pages size1021rc && ls cache >output && test_line_count = 13 output && - cgit_url "foo/ls_cache" >output.full && + cgit_ok size1021rc "url=foo/ls_cache" >output.full && strip_headers <output.full >output && test_line_count = 13 output && - cgit_url "foo/ls_cache" >output.second && + ls cache >output && + test_line_count = 14 output && + cgit_ok size1021rc "url=foo/ls_cache" >output.second && test_cmp output.full output.second ' |
