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