Skip to content

Commit

Permalink
SQUASHME: increase stale waitlist hit coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dridi committed Sep 28, 2023
1 parent 52aef2c commit 235f17c
Showing 1 changed file with 85 additions and 3 deletions.
88 changes: 85 additions & 3 deletions bin/varnishtest/tests/c00125.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,64 @@ varnishtest "successful expired waiting list hit"

barrier b1 cond 2
barrier b2 cond 2
barrier b3 cond 2
barrier b4 cond 2


server s1 {
rxreq
expect req.http.user-agent == c1
expect req.http.bgfetch == false
barrier b1 sync
barrier b2 sync
txresp -hdr "Cache-Control: max-age=60" -hdr "Age: 120"

rxreq
expect req.http.user-agent == c3
expect req.http.bgfetch == true
txresp

# The no-cache case only works with a complicit VCL, for now.
rxreq
expect req.http.user-agent == c4
expect req.http.bgfetch == false
barrier b3 sync
barrier b4 sync
txresp -hdr "Cache-Control: no-cache"

rxreq
expect req.http.user-agent == c6
expect req.http.bgfetch == false
txresp -hdr "Cache-Control: no-cache"
} -start

varnish v1 -cliok "param.set default_grace 1h"
varnish v1 -cliok "param.set thread_pools 1"
varnish v1 -cliok "param.set debug +syncvsl,+waitinglist"
varnish v1 -vcl+backend {
sub vcl_backend_fetch {
set bereq.http.bgfetch = bereq.is_bgfetch;
}
sub vcl_beresp_stale {
# We just validated a stale object, do not mark it as
# uncacheable. The object remains available for grace
# hits and background fetches.
return;
}
sub vcl_beresp_control {
if (beresp.http.cache-control == "no-cache") {
# Keep beresp.uncacheable clear.
return;
}
}
sub vcl_deliver {
set resp.http.obj-hits = obj.hits;
set resp.http.obj-ttl = obj.ttl;
}
} -start

client c1 {
txreq
txreq -url "/stale-hit"
rxresp
expect resp.status == 200
expect resp.http.x-varnish == 1001
Expand All @@ -38,7 +70,7 @@ client c1 {
barrier b1 sync

client c2 {
txreq
txreq -url "/stale-hit"
rxresp
expect resp.status == 200
expect resp.http.x-varnish == "1004 1002"
Expand All @@ -60,7 +92,7 @@ varnish v1 -expect cache_hit_grace == 0
varnish v1 -expect s_bgfetch == 0

client c3 {
txreq
txreq -url "/stale-hit"
rxresp
expect resp.status == 200
expect resp.http.x-varnish == "1006 1002"
Expand All @@ -70,5 +102,55 @@ client c3 {

varnish v1 -vsl_catchup

varnish v1 -expect cache_miss == 1
varnish v1 -expect cache_hit == 2
varnish v1 -expect cache_hit_grace == 1
varnish v1 -expect s_bgfetch == 1

# The only way for a plain no-cache to be hit is to have a non-zero keep.
varnish v1 -cliok "param.set default_ttl 0"
varnish v1 -cliok "param.set default_grace 0"
varnish v1 -cliok "param.set default_keep 1h"

client c4 {
txreq -url "/no-cache-hit"
rxresp
expect resp.status == 200
expect resp.http.x-varnish == 1009
expect resp.http.obj-hits == 0
expect resp.http.obj-ttl <= 0
} -start

barrier b3 sync

client c5 {
txreq -url "/no-cache-hit"
rxresp
expect resp.status == 200
expect resp.http.x-varnish == "1012 1010"
expect resp.http.obj-hits == 1
expect resp.http.obj-ttl <= 0
} -start

varnish v1 -expect busy_sleep == 2
barrier b4 sync

client c4 -wait
client c5 -wait

varnish v1 -vsl_catchup

varnish v1 -expect cache_miss == 2
varnish v1 -expect cache_hit == 3
varnish v1 -expect cache_hit_grace == 1
varnish v1 -expect s_bgfetch == 1

# No hit when not on the waiting list
client c6 {
txreq -url "/no-cache-hit"
rxresp
expect resp.status == 200
expect resp.http.x-varnish == 1014
expect resp.http.obj-hits == 0
expect resp.http.obj-ttl <= 0
} -run

0 comments on commit 235f17c

Please sign in to comment.