blob: add6366eb41ae7f5fcd7d195eb0ad39a45680d6a [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
Remi Tricot-Le Bretoncc9bf2e2020-11-12 11:14:41 +010010 txresp -nolen -hdr "Transfer-Encoding: chunked" \
11 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010012 chunkedlen 15
13 chunkedlen 15
14 chunkedlen 15
15 chunkedlen 0
16} -start
17
18server s2 {
19 rxreq
Remi Tricot-Le Bretoncc9bf2e2020-11-12 11:14:41 +010020 txresp -nolen -hdr "Transfer-Encoding: chunked" \
21 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010022 chunkedlen 16
23 chunkedlen 16
24 chunkedlen 16
25 chunkedlen 0
26} -start
27
28server s3 {
29 rxreq
Remi Tricot-Le Bretoncc9bf2e2020-11-12 11:14:41 +010030 txresp -nolen -hdr "Transfer-Encoding: chunked" \
31 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010032 chunkedlen 17
33 chunkedlen 17
34 chunkedlen 17
35 chunkedlen 0
36
37 rxreq
Remi Tricot-Le Bretoncc9bf2e2020-11-12 11:14:41 +010038 txresp -nolen -hdr "Transfer-Encoding: chunked" \
39 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010040 chunkedlen 17
41 chunkedlen 17
42 chunkedlen 17
43 chunkedlen 0
44} -start
45
46haproxy h1 -conf {
Willy Tarreaue1465c12021-05-09 14:41:41 +020047 global
48 # WT: limit false-positives causing "HTTP header incomplete" due to
49 # idle server connections being randomly used and randomly expiring
50 # under us.
51 tune.idle-pool.shared off
52
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010053 defaults
54 mode http
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010055 timeout connect 1s
56 timeout client 1s
57 timeout server 1s
58
59 frontend fe
60 bind "fd@${fe}"
61 use_backend first_be if { path_beg /first }
62 use_backend nocache_be if { path_beg /nocache }
63 default_backend second_be
64
65 backend first_be
66 http-request cache-use first_cache
67 server www ${s1_addr}:${s1_port}
68 http-response cache-store first_cache
69 http-response set-header X-Cache-Hit %[res.cache_hit]
70 http-response set-header X-Cache-Name %[res.cache_name]
71
72 backend second_be
73 http-request cache-use second_cache
74 server www ${s2_addr}:${s2_port}
75 http-response cache-store second_cache
76 http-response set-header X-Cache-Hit %[res.cache_hit]
77 http-response set-header X-Cache-Name %[res.cache_name]
78
79 backend nocache_be
80 server www ${s3_addr}:${s3_port}
81 http-response set-header X-Cache-Hit %[res.cache_hit]
82 http-response set-header X-Cache-Name %[res.cache_name]
83
84 cache first_cache
85 total-max-size 3
86 max-age 40
87 max-object-size 3000
88
89 cache second_cache
90 total-max-size 3
91 max-age 20
92 max-object-size 3072
93} -start
94
95
96client c1 -connect ${h1_fe_sock} {
97 txreq -url "/first"
98 rxresp
99 expect resp.status == 200
100 expect resp.bodylen == 45
101 expect resp.http.X-Cache-Hit == 0
102 expect resp.http.X-Cache-Name == ""
103
104 txreq -url "/second"
105 rxresp
106 expect resp.status == 200
107 expect resp.bodylen == 48
108 expect resp.http.X-Cache-Hit == 0
109 expect resp.http.X-Cache-Name == ""
110
111 txreq -url "/nocache"
112 rxresp
113 expect resp.status == 200
114 expect resp.bodylen == 51
115 expect resp.http.X-Cache-Hit == 0
116 expect resp.http.X-Cache-Name == ""
117
118 # Response should come form the cache now
119 txreq -url "/nocache"
120 rxresp
121 expect resp.status == 200
122 expect resp.bodylen == 51
123 expect resp.http.X-Cache-Hit == 0
124 expect resp.http.X-Cache-Name == ""
125
126 txreq -url "/first"
127 rxresp
128 expect resp.status == 200
129 expect resp.bodylen == 45
130 expect resp.http.X-Cache-Hit == 1
131 expect resp.http.X-Cache-Name == "first_cache"
132
133 txreq -url "/second"
134 rxresp
135 expect resp.status == 200
136 expect resp.bodylen == 48
137 expect resp.http.X-Cache-Hit == 1
138 expect resp.http.X-Cache-Name == "second_cache"
139} -run