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