Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 1 | |
| 2 | varnishtest "Basic cache test" |
| 3 | |
Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 4 | feature ignore_unknown_macro |
| 5 | |
| 6 | server s1 { |
| 7 | rxreq |
Remi Tricot-Le Breton | cc9bf2e | 2020-11-12 11:14:41 +0100 | [diff] [blame] | 8 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 9 | -hdr "Cache-Control: max-age=5" |
Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 10 | chunkedlen 15 |
| 11 | chunkedlen 15 |
| 12 | chunkedlen 15 |
| 13 | chunkedlen 0 |
| 14 | } -start |
| 15 | |
| 16 | server s2 { |
| 17 | rxreq |
Remi Tricot-Le Breton | cc9bf2e | 2020-11-12 11:14:41 +0100 | [diff] [blame] | 18 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 19 | -hdr "Cache-Control: max-age=5" |
Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 20 | chunkedlen 16 |
| 21 | chunkedlen 16 |
| 22 | chunkedlen 16 |
| 23 | chunkedlen 0 |
| 24 | } -start |
| 25 | |
| 26 | server s3 { |
| 27 | rxreq |
Remi Tricot-Le Breton | cc9bf2e | 2020-11-12 11:14:41 +0100 | [diff] [blame] | 28 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 29 | -hdr "Cache-Control: max-age=5" |
Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 30 | chunkedlen 17 |
| 31 | chunkedlen 17 |
| 32 | chunkedlen 17 |
| 33 | chunkedlen 0 |
| 34 | |
| 35 | rxreq |
Remi Tricot-Le Breton | cc9bf2e | 2020-11-12 11:14:41 +0100 | [diff] [blame] | 36 | txresp -nolen -hdr "Transfer-Encoding: chunked" \ |
| 37 | -hdr "Cache-Control: max-age=5" |
Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 38 | chunkedlen 17 |
| 39 | chunkedlen 17 |
| 40 | chunkedlen 17 |
| 41 | chunkedlen 0 |
| 42 | } -start |
| 43 | |
| 44 | haproxy h1 -conf { |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 45 | 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 Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 51 | defaults |
| 52 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 53 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
| 54 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 55 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
Remi Tricot-Le Breton | bf97121 | 2020-10-27 11:55:57 +0100 | [diff] [blame] | 56 | |
| 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 | |
| 94 | client 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 |