Skip to content

Commit e1b6a5e

Browse files
committed
ACP2E-4232: Investigate if AC-7784 can be automated
1 parent 0a8c9a9 commit e1b6a5e

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
varnishtest "X-Magento-Vary handling (varnish7)"
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+
# Non-GraphQL with X-Magento-Vary => uncacheable (backend hit twice)
14+
rxreq
15+
expect req.url == "/"
16+
txresp -status 200 \
17+
-hdr "Cache-Control: max-age=600" \
18+
-hdr "Set-Cookie: X-Magento-Vary=abc; Path=/; HttpOnly" \
19+
-body "non-graphql-1"
20+
21+
rxreq
22+
expect req.url == "/"
23+
txresp -status 200 \
24+
-hdr "Cache-Control: max-age=600" \
25+
-hdr "Set-Cookie: X-Magento-Vary=abc; Path=/; HttpOnly" \
26+
-body "non-graphql-2"
27+
28+
# GraphQL with X-Magento-Cache-Id => cacheable (backend hit once)
29+
rxreq
30+
expect req.url == "/graphql"
31+
expect req.http.X-Magento-Cache-Id == "id-1"
32+
txresp -status 200 \
33+
-hdr "Cache-Control: max-age=600" \
34+
-hdr "Set-Cookie: X-Magento-Vary=abc; Path=/; HttpOnly" \
35+
-hdr "X-Magento-Cache-Id: id-1" \
36+
-body "graphql-1"
37+
38+
# Multiple Set-Cookie with X-Magento-Vary => uncacheable (backend hit twice)
39+
rxreq
40+
expect req.url == "/multi"
41+
txresp -status 200 \
42+
-hdr "Cache-Control: max-age=600" \
43+
-hdr "Set-Cookie: foo=bar; Path=/; HttpOnly" \
44+
-hdr "Set-Cookie: X-Magento-Vary=abc; Path=/; HttpOnly" \
45+
-body "multi-1"
46+
47+
rxreq
48+
expect req.url == "/multi"
49+
txresp -status 200 \
50+
-hdr "Cache-Control: max-age=600" \
51+
-hdr "Set-Cookie: baz=qux; Path=/; HttpOnly" \
52+
-hdr "Set-Cookie: X-Magento-Vary=abc; Path=/; HttpOnly" \
53+
-body "multi-2"
54+
} -start
55+
56+
# generate usable VCL pointing towards s1
57+
shell {
58+
sed \
59+
-e 's@\.interval = 5s;@.interval = 5m; .initial = 10;@' \
60+
-e 's@/\* {{ host }} \*/@${s1_addr}@' \
61+
-e 's@/\* {{ port }} \*/@${s1_port}@' \
62+
-e 's@/\* {{ ssl_offloaded_header }} \*/@unused@' \
63+
-e 's@/\* {{ grace_period }} \*/@0@' \
64+
${testdir}/../../../app/code/Magento/PageCache/etc/varnish7.vcl > ${tmpdir}/output.vcl
65+
}
66+
67+
varnish v1 -arg "-f" -arg "${tmpdir}/output.vcl" -start
68+
69+
# make sure the probe request fired
70+
delay 1
71+
72+
client c1 {
73+
# Test 1: Non-GraphQL with X-Magento-Vary => uncacheable
74+
txreq -url "/"
75+
rxresp
76+
expect resp.status == 200
77+
expect resp.http.Set-Cookie == "<undef>"
78+
expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
79+
expect resp.body ~ "non-graphql-1"
80+
81+
txreq -url "/"
82+
rxresp
83+
expect resp.status == 200
84+
expect resp.http.Set-Cookie == "<undef>"
85+
expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
86+
expect resp.body ~ "non-graphql-2"
87+
88+
# Test 2: GraphQL with X-Magento-Cache-Id => cacheable
89+
txreq -url "/graphql" -hdr "X-Magento-Cache-Id: id-1"
90+
rxresp
91+
expect resp.status == 200
92+
expect resp.http.Set-Cookie == "<undef>"
93+
expect resp.http.X-Magento-Cache-Debug == "MISS"
94+
expect resp.body ~ "graphql-1"
95+
96+
txreq -url "/graphql" -hdr "X-Magento-Cache-Id: id-1"
97+
rxresp
98+
expect resp.status == 200
99+
expect resp.http.Set-Cookie == "<undef>"
100+
expect resp.http.X-Magento-Cache-Debug == "HIT"
101+
expect resp.body ~ "graphql-1"
102+
103+
# Test 3: Multiple Set-Cookie with X-Magento-Vary => uncacheable
104+
txreq -url "/multi"
105+
rxresp
106+
expect resp.status == 200
107+
expect resp.http.Set-Cookie == "<undef>"
108+
expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
109+
expect resp.body ~ "multi-1"
110+
111+
txreq -url "/multi"
112+
rxresp
113+
expect resp.status == 200
114+
expect resp.http.Set-Cookie == "<undef>"
115+
expect resp.http.X-Magento-Cache-Debug == "UNCACHEABLE"
116+
expect resp.body ~ "multi-2"
117+
} -run
118+
119+
# make sure s1 saw all the requests it was expecting
120+
server s1 -wait
121+

0 commit comments

Comments
 (0)