Skip to content

Commit f4e3b54

Browse files
gquintardhostep
authored andcommitted
[vcl] test uncacheability rules
(cherry picked from commit ca32d5a)
1 parent 0618ef9 commit f4e3b54

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

dev/tests/varnish/no-caching.vtc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
varnishtest "X-Magento-Cache-Debug header"
2+
3+
server s1 {
4+
# first request will be the probe, handle it and be on our way
5+
rxreq
6+
expect req.url == "/health_check.php"
7+
txresp
8+
9+
# the probe expects the connection to close
10+
close
11+
accept
12+
13+
# the client will send 2 requests for each url, the server should only see one
14+
# of each in the cacheable case, and two otherwise
15+
16+
# 405, Cache-Control doesn't matter
17+
loop 2 {
18+
rxreq
19+
expect req.url == "/405uncacheable"
20+
txresp -status 405
21+
}
22+
23+
# 200, private Cache-Control
24+
loop 2 {
25+
rxreq
26+
expect req.url == "/200uncacheable"
27+
txresp -status 200 -hdr "cache-control: private"
28+
}
29+
30+
# 404, private Cache-Control
31+
loop 2 {
32+
rxreq
33+
expect req.url == "/404uncacheable"
34+
txresp -status 200 -hdr "cache-control: private"
35+
}
36+
37+
# 200, no Cache-Control
38+
rxreq
39+
expect req.url == "/200cacheable"
40+
txresp -status 200
41+
42+
# 404, but still no Cache-Control
43+
rxreq
44+
expect req.url == "/404cacheable"
45+
txresp -status 404
46+
} -start
47+
48+
# generate usable VCL pointing towards s1
49+
# mostly, we replace the place-holders, but we also jack up the probe
50+
# interval to avoid further interference
51+
shell {
52+
# testdir is automatically set to the directory containing the present vtc
53+
sed \
54+
-e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \
55+
-e 's@/\* {{ host }} \*/@${s1_addr}@' \
56+
-e 's@/\* {{ port }} \*/@${s1_port}@' \
57+
-e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \
58+
-e 's@/\* {{ grace_period }} \*/@0@' \
59+
${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl
60+
}
61+
62+
varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -start
63+
64+
# make sure the probe request fired
65+
delay 1
66+
67+
client c1 {
68+
loop 2 {
69+
txreq -url /405uncacheable
70+
rxresp
71+
}
72+
73+
loop 2 {
74+
txreq -url /200uncacheable
75+
rxresp
76+
}
77+
78+
loop 2 {
79+
txreq -url /404uncacheable
80+
rxresp
81+
}
82+
83+
loop 2 {
84+
txreq -url /200cacheable
85+
rxresp
86+
}
87+
88+
loop 2 {
89+
txreq -url /404cacheable
90+
rxresp
91+
}
92+
} -run
93+
94+
# make sure s1 saw all the requests it was expecting
95+
server s1 -wait

0 commit comments

Comments
 (0)