blob: 1ba069022144a67e7d45241a6bcd68a67055e0fc [file] [log] [blame]
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +01001
2varnishtest "Basic cache test"
3
4#REQUIRE_VERSION=1.9
5
6feature ignore_unknown_macro
7
8server s1 {
9 rxreq
10 txresp -nolen -hdr "Transfer-Encoding: chunked"
11 chunkedlen 15
12 chunkedlen 15
13 chunkedlen 15
14 chunkedlen 0
15} -start
16
17server s2 {
18 rxreq
19 txresp -nolen -hdr "Transfer-Encoding: chunked"
20 chunkedlen 16
21 chunkedlen 16
22 chunkedlen 16
23 chunkedlen 0
24} -start
25
26server s3 {
27 rxreq
28 txresp -nolen -hdr "Transfer-Encoding: chunked"
29 chunkedlen 17
30 chunkedlen 17
31 chunkedlen 17
32 chunkedlen 0
33
34 rxreq
35 txresp -nolen -hdr "Transfer-Encoding: chunked"
36 chunkedlen 17
37 chunkedlen 17
38 chunkedlen 17
39 chunkedlen 0
40} -start
41
42haproxy h1 -conf {
43 defaults
44 mode http
45 ${no-htx} option http-use-htx
46 timeout connect 1s
47 timeout client 1s
48 timeout server 1s
49
50 frontend fe
51 bind "fd@${fe}"
52 use_backend first_be if { path_beg /first }
53 use_backend nocache_be if { path_beg /nocache }
54 default_backend second_be
55
56 backend first_be
57 http-request cache-use first_cache
58 server www ${s1_addr}:${s1_port}
59 http-response cache-store first_cache
60 http-response set-header X-Cache-Hit %[res.cache_hit]
61 http-response set-header X-Cache-Name %[res.cache_name]
62
63 backend second_be
64 http-request cache-use second_cache
65 server www ${s2_addr}:${s2_port}
66 http-response cache-store second_cache
67 http-response set-header X-Cache-Hit %[res.cache_hit]
68 http-response set-header X-Cache-Name %[res.cache_name]
69
70 backend nocache_be
71 server www ${s3_addr}:${s3_port}
72 http-response set-header X-Cache-Hit %[res.cache_hit]
73 http-response set-header X-Cache-Name %[res.cache_name]
74
75 cache first_cache
76 total-max-size 3
77 max-age 40
78 max-object-size 3000
79
80 cache second_cache
81 total-max-size 3
82 max-age 20
83 max-object-size 3072
84} -start
85
86
87client c1 -connect ${h1_fe_sock} {
88 txreq -url "/first"
89 rxresp
90 expect resp.status == 200
91 expect resp.bodylen == 45
92 expect resp.http.X-Cache-Hit == 0
93 expect resp.http.X-Cache-Name == ""
94
95 txreq -url "/second"
96 rxresp
97 expect resp.status == 200
98 expect resp.bodylen == 48
99 expect resp.http.X-Cache-Hit == 0
100 expect resp.http.X-Cache-Name == ""
101
102 txreq -url "/nocache"
103 rxresp
104 expect resp.status == 200
105 expect resp.bodylen == 51
106 expect resp.http.X-Cache-Hit == 0
107 expect resp.http.X-Cache-Name == ""
108
109 # Response should come form the cache now
110 txreq -url "/nocache"
111 rxresp
112 expect resp.status == 200
113 expect resp.bodylen == 51
114 expect resp.http.X-Cache-Hit == 0
115 expect resp.http.X-Cache-Name == ""
116
117 txreq -url "/first"
118 rxresp
119 expect resp.status == 200
120 expect resp.bodylen == 45
121 expect resp.http.X-Cache-Hit == 1
122 expect resp.http.X-Cache-Name == "first_cache"
123
124 txreq -url "/second"
125 rxresp
126 expect resp.status == 200
127 expect resp.bodylen == 48
128 expect resp.http.X-Cache-Hit == 1
129 expect resp.http.X-Cache-Name == "second_cache"
130} -run