This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
Files in this directory are Varnish Test Cases (VTC) and check the behavior of the VCL file shipped by `magento2`.
Varnish needs to be installed, but then the test scenarios can be run individually or all at once:
``` shell
varnishtest *.vtc
```
Documentation:
- varnishtest itself: https://varnish-cache.org/docs/trunk/reference/varnishtest.html
- VTC syntax: https://varnish-cache.org/docs/trunk/reference/vtc.html
+66
View File
@@ -0,0 +1,66 @@
varnishtest "Compression handling"
server s1 {
# first request will be the probe, handle it and be on our way
rxreq
expect req.url == "/health_check.php"
txresp
# the probe expects the connection to close
close
accept
# reply with a 200
loop 4 {
rxreq
txresp -hdr "answer-to: POST"
}
rxreq
txresp -hdr "answer-to: GET"
} -start
# generate usable VCL pointing towards s1
# mostly, we replace the place-holders, but we also jack up the probe
# interval to avoid further interference
shell {
# testdir is automatically set to the directory containing the present vtc
sed \
-e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \
-e 's@/\* {{ host }} \*/@${s1_addr}@' \
-e 's@/\* {{ port }} \*/@${s1_port}@' \
-e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \
-e 's@/\* {{ grace_period }} \*/@0@' \
${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl
}
# little trick here: we leverage the fact that subroutines with the same name
# are concatenated in the order they are seen. This allows us to tweak the
# backend response before the official VCL processes it, so we can tell
# client c1 which AE header was sent to the backend
varnish v1 -vcl {
sub vcl_backend_response {
set beresp.http.sent-accept-encoding = bereq.http.accept-encoding;
}
include "${tmpdir}/output.vcl";
}-start
# make sur ethe probe request fired
delay 1
client c1 {
# Uncacheable (it's a POST), Varnish should send it verbatim to s1
txreq -method "POST" -hdr "accept-encoding: something completely random"
rxresp
expect resp.http.sent-accept-encoding == "something completely random"
# cacheable GET
txreq -hdr "accept-encoding: will be overridden"
rxresp
expect resp.http.sent-accept-encoding == "gzip"
# same thing, but the extension suggest an already compressed response
txreq -url "/foo.tgz" -hdr "accept-encoding: will be overridden"
rxresp
expect resp.http.sent-accept-encoding == "gzip"
} -run
+54
View File
@@ -0,0 +1,54 @@
varnishtest "X-Magento-Cache-Debug header"
server s1 {
# first request will be the probe, handle it and be on our way
rxreq
expect req.url == "/health_check.php"
txresp
# the probe expects the connection to close
close
accept
rxreq
txresp -hdr "answer-to: POST"
rxreq
txresp -hdr "answer-to: GET"
} -start
# generate usable VCL pointing towards s1
# mostly, we replace the place-holders, but we also jack up the probe
# interval to avoid further interference
shell {
# testdir is automatically set to the directory containing the present vtc
sed \
-e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \
-e 's@/\* {{ host }} \*/@${s1_addr}@' \
-e 's@/\* {{ port }} \*/@${s1_port}@' \
-e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \
-e 's@/\* {{ grace_period }} \*/@0@' \
${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl
}
varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -start
# make surethe probe request fired
delay 1
client c1 {
txreq -method "POST"
rxresp
expect resp.http.answer-to == "POST"
expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
txreq
rxresp
expect resp.http.answer-to == "GET"
expect resp.http.X-Magento-Cache-Debug == "MISS"
txreq
rxresp
expect resp.http.answer-to == "GET"
expect resp.http.X-Magento-Cache-Debug == "HIT"
} -run
+95
View File
@@ -0,0 +1,95 @@
varnishtest "X-Magento-Cache-Debug header"
server s1 {
# first request will be the probe, handle it and be on our way
rxreq
expect req.url == "/health_check.php"
txresp
# the probe expects the connection to close
close
accept
# the client will send 2 requests for each url, the server should only see one
# of each in the cacheable case, and two otherwise
# 405, Cache-Control doesn't matter
loop 2 {
rxreq
expect req.url == "/405uncacheable"
txresp -status 405
}
# 200, private Cache-Control
loop 2 {
rxreq
expect req.url == "/200uncacheable"
txresp -status 200 -hdr "cache-control: private"
}
# 404, private Cache-Control
loop 2 {
rxreq
expect req.url == "/404uncacheable"
txresp -status 200 -hdr "cache-control: private"
}
# 200, no Cache-Control
rxreq
expect req.url == "/200cacheable"
txresp -status 200
# 404, but still no Cache-Control
rxreq
expect req.url == "/404cacheable"
txresp -status 404
} -start
# generate usable VCL pointing towards s1
# mostly, we replace the place-holders, but we also jack up the probe
# interval to avoid further interference
shell {
# testdir is automatically set to the directory containing the present vtc
sed \
-e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \
-e 's@/\* {{ host }} \*/@${s1_addr}@' \
-e 's@/\* {{ port }} \*/@${s1_port}@' \
-e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \
-e 's@/\* {{ grace_period }} \*/@0@' \
${testdir}/../../../app/code/Magento/PageCache/etc/varnish6.vcl > ${tmpdir}/output.vcl
}
varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -start
# make sure the probe request fired
delay 1
client c1 {
loop 2 {
txreq -url /405uncacheable
rxresp
}
loop 2 {
txreq -url /200uncacheable
rxresp
}
loop 2 {
txreq -url /404uncacheable
rxresp
}
loop 2 {
txreq -url /200cacheable
rxresp
}
loop 2 {
txreq -url /404cacheable
rxresp
}
} -run
# make sure s1 saw all the requests it was expecting
server s1 -wait