Skip to content

Commit 7d7bf7d

Browse files
committed
Merge remote-tracking branch '38211/vcl_debug' into 247beta3_jan
2 parents 4ce4490 + f116c9c commit 7d7bf7d

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ sub vcl_backend_response {
204204
}
205205

206206
sub vcl_deliver {
207-
if (resp.http.x-varnish ~ " ") {
207+
if (obj.uncacheable) {
208+
set resp.http.X-Magento-Cache-Debug = "UNCACHEABLE";
209+
} else if (obj.hits) {
208210
set resp.http.X-Magento-Cache-Debug = "HIT";
209211
set resp.http.Grace = req.http.grace;
210212
} else {

dev/tests/varnish/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Files in this directory are Varnish Test Cases (VTC) and check the behavior of the VCL file shipped by `magento2`.
2+
3+
Varnish needs to be installed, but then the test scenarios can be run individually or all at once:
4+
5+
``` shell
6+
varnishtest *.vtc
7+
```
8+
9+
Documentation:
10+
- varnishtest itself: https://varnish-cache.org/docs/trunk/reference/varnishtest.html
11+
- VTC syntax: https://varnish-cache.org/docs/trunk/reference/vtc.html

dev/tests/varnish/debug.vtc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
rxreq
14+
txresp -hdr "answer-to: POST"
15+
16+
rxreq
17+
txresp -hdr "answer-to: GET"
18+
} -start
19+
20+
# generate usable VCL pointing towards s1
21+
# mostly, we replace the place-holders, but we also jack up the probe
22+
# interval to avoid further interference
23+
shell {
24+
# testdir is automatically set to the directory containing the present vtc
25+
sed \
26+
-e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \
27+
-e 's@/\* {{ host }} \*/@${s1_addr}@' \
28+
-e 's@/\* {{ port }} \*/@${s1_port}@' \
29+
-e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \
30+
-e 's@/\* {{ grace_period }} \*/@0@' \
31+
${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl
32+
}
33+
34+
varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -start
35+
36+
# make surethe probe request fired
37+
delay 1
38+
39+
client c1 {
40+
txreq -method "POST"
41+
rxresp
42+
expect resp.http.answer-to == "POST"
43+
expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
44+
45+
txreq
46+
rxresp
47+
expect resp.http.answer-to == "GET"
48+
expect resp.http.X-Magento-Cache-Debug == "MISS"
49+
50+
txreq
51+
rxresp
52+
expect resp.http.answer-to == "GET"
53+
expect resp.http.X-Magento-Cache-Debug == "HIT"
54+
} -run

0 commit comments

Comments
 (0)