blob: 973b3ad61e2dd8185eb534d83d31ab0c48354612 [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
55 ${no-htx} option http-use-htx
56 timeout connect 1s
57 timeout client 1s
58 timeout server 1s
59
60 frontend fe
61 bind "fd@${fe}"
62 use_backend first_be if { path_beg /first }
63 use_backend nocache_be if { path_beg /nocache }
64 default_backend second_be
65
66 backend first_be
67 http-request cache-use first_cache
68 server www ${s1_addr}:${s1_port}
69 http-response cache-store first_cache
70 http-response set-header X-Cache-Hit %[res.cache_hit]
71 http-response set-header X-Cache-Name %[res.cache_name]
72
73 backend second_be
74 http-request cache-use second_cache
75 server www ${s2_addr}:${s2_port}
76 http-response cache-store second_cache
77 http-response set-header X-Cache-Hit %[res.cache_hit]
78 http-response set-header X-Cache-Name %[res.cache_name]
79
80 backend nocache_be
81 server www ${s3_addr}:${s3_port}
82 http-response set-header X-Cache-Hit %[res.cache_hit]
83 http-response set-header X-Cache-Name %[res.cache_name]
84
85 cache first_cache
86 total-max-size 3
87 max-age 40
88 max-object-size 3000
89
90 cache second_cache
91 total-max-size 3
92 max-age 20
93 max-object-size 3072
94} -start
95
96
97client c1 -connect ${h1_fe_sock} {
98 txreq -url "/first"
99 rxresp
100 expect resp.status == 200
101 expect resp.bodylen == 45
102 expect resp.http.X-Cache-Hit == 0
103 expect resp.http.X-Cache-Name == ""
104
105 txreq -url "/second"
106 rxresp
107 expect resp.status == 200
108 expect resp.bodylen == 48
109 expect resp.http.X-Cache-Hit == 0
110 expect resp.http.X-Cache-Name == ""
111
112 txreq -url "/nocache"
113 rxresp
114 expect resp.status == 200
115 expect resp.bodylen == 51
116 expect resp.http.X-Cache-Hit == 0
117 expect resp.http.X-Cache-Name == ""
118
119 # Response should come form the cache now
120 txreq -url "/nocache"
121 rxresp
122 expect resp.status == 200
123 expect resp.bodylen == 51
124 expect resp.http.X-Cache-Hit == 0
125 expect resp.http.X-Cache-Name == ""
126
127 txreq -url "/first"
128 rxresp
129 expect resp.status == 200
130 expect resp.bodylen == 45
131 expect resp.http.X-Cache-Hit == 1
132 expect resp.http.X-Cache-Name == "first_cache"
133
134 txreq -url "/second"
135 rxresp
136 expect resp.status == 200
137 expect resp.bodylen == 48
138 expect resp.http.X-Cache-Hit == 1
139 expect resp.http.X-Cache-Name == "second_cache"
140} -run