Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 1 | varnishtest "Health-checks: some http-check tests" |
| 2 | feature ignore_unknown_macro |
| 3 | #REQUIRE_VERSION=2.2 |
| 4 | #REGTEST_TYPE=slow |
| 5 | # This script tests HTTP health-checks. |
| 6 | |
| 7 | server s1 { |
| 8 | rxreq |
| 9 | expect req.method == OPTIONS |
| 10 | expect req.url == / |
| 11 | expect req.proto == HTTP/1.0 |
| 12 | txresp |
| 13 | } -start |
| 14 | |
| 15 | server s2 { |
| 16 | rxreq |
| 17 | expect req.method == GET |
| 18 | expect req.url == /status |
| 19 | expect req.proto == HTTP/1.1 |
| 20 | txresp |
| 21 | } -start |
| 22 | |
| 23 | server s3 { |
| 24 | rxreq |
| 25 | expect req.method == GET |
| 26 | expect req.url == /status |
| 27 | expect req.proto == HTTP/1.1 |
| 28 | txresp |
| 29 | } -start |
| 30 | |
| 31 | server s4 { |
| 32 | rxreq |
| 33 | expect req.method == GET |
| 34 | expect req.url == /req1 |
| 35 | expect req.proto == HTTP/1.1 |
| 36 | expect req.http.x-test == "server=srv" |
| 37 | expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv" |
| 38 | expect req.bodylen == 0 |
| 39 | txresp |
| 40 | |
| 41 | accept |
| 42 | rxreq |
| 43 | expect req.method == GET |
| 44 | expect req.url == /req2 |
| 45 | expect req.proto == HTTP/1.1 |
| 46 | expect req.http.x-test == "server=" |
| 47 | expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv" |
| 48 | expect req.http.content-length == 17 |
| 49 | expect req.bodylen == 17 |
| 50 | expect req.body == "health-check body" |
| 51 | txresp |
| 52 | |
| 53 | accept |
| 54 | rxreq |
| 55 | expect req.method == GET |
| 56 | expect req.url == /req3 |
| 57 | expect req.proto == HTTP/1.0 |
| 58 | expect req.http.x-test == <undef> |
| 59 | expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv" |
| 60 | expect req.bodylen == 0 |
| 61 | txresp |
| 62 | |
Christopher Faulet | 7c95f5f | 2020-05-06 15:06:34 +0200 | [diff] [blame] | 63 | accept |
| 64 | rxreq |
| 65 | expect req.method == GET |
| 66 | expect req.url == / |
| 67 | expect req.proto == HTTP/1.0 |
| 68 | expect req.http.x-test == <undef> |
| 69 | expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv" |
Christopher Faulet | 574e7bd | 2020-05-06 15:38:58 +0200 | [diff] [blame] | 70 | expect req.bodylen == 23 |
| 71 | expect req.body == "health-check on be4-srv" |
Christopher Faulet | 7c95f5f | 2020-05-06 15:06:34 +0200 | [diff] [blame] | 72 | txresp |
| 73 | |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 74 | } -start |
| 75 | |
| 76 | syslog S1 -level notice { |
| 77 | recv |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 78 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
| 79 | recv |
| 80 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
| 81 | recv |
| 82 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
| 83 | recv |
| 84 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 85 | recv |
| 86 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
| 87 | recv |
| 88 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 89 | } -start |
| 90 | |
| 91 | haproxy h1 -conf { |
| 92 | defaults |
| 93 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 94 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 95 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 96 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 97 | option log-health-checks |
| 98 | |
| 99 | backend be1 |
| 100 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 101 | option httpchk |
| 102 | server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1 |
| 103 | |
| 104 | backend be2 |
| 105 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 106 | option httpchk GET /status HTTP/1.1 |
| 107 | server srv ${s2_addr}:${s2_port} check inter 100ms rise 1 fall 1 |
| 108 | |
| 109 | backend be3 |
| 110 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 111 | option httpchk |
Christopher Faulet | 907701b | 2020-04-28 09:37:00 +0200 | [diff] [blame] | 112 | http-check send meth GET uri /status ver HTTP/1.1 |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 113 | server srv ${s3_addr}:${s3_port} check inter 100ms rise 1 fall 1 |
| 114 | |
| 115 | backend be4 |
| 116 | mode tcp |
| 117 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 118 | option httpchk |
| 119 | http-check send-state |
| 120 | http-check connect addr ${s4_addr}:${s4_port} |
| 121 | http-check set-var(check.server) "str(srv)" |
Christopher Faulet | 7c95f5f | 2020-05-06 15:06:34 +0200 | [diff] [blame] | 122 | http-check set-var(check.path) "str(/req1)" |
| 123 | http-check send meth GET uri-lf "%[var(check.path)]" ver HTTP/1.1 hdr x-test "server=%[var(check.server)]" |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 124 | http-check expect status 200 |
| 125 | http-check connect addr ${s4_addr} port ${s4_port} |
| 126 | http-check unset-var(check.server) |
Christopher Faulet | 7c95f5f | 2020-05-06 15:06:34 +0200 | [diff] [blame] | 127 | http-check set-var(check.path) "str(/req2)" |
| 128 | http-check send meth GET uri-lf "%[var(check.path)]" ver HTTP/1.1 hdr x-test "server=%[var(check.server)]" body "health-check body" |
| 129 | http-check expect rstatus "^2[0-9]{2}" |
| 130 | http-check connect addr ${s4_addr} port ${s4_port} |
| 131 | http-check set-var(check.path) "str(/req3)" |
| 132 | http-check send meth GET uri-lf "%[var(check.path)]" |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 133 | http-check expect rstatus "^2[0-9]{2}" |
| 134 | http-check connect addr ${s4_addr} port ${s4_port} |
Christopher Faulet | 7c95f5f | 2020-05-06 15:06:34 +0200 | [diff] [blame] | 135 | http-check unset-var(check.path) |
Christopher Faulet | 574e7bd | 2020-05-06 15:38:58 +0200 | [diff] [blame] | 136 | http-check send meth GET uri-lf "%[var(check.path)]" body-lf "health-check on %[be_name]-%[srv_name]" |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 137 | ## implicit expect rule |
| 138 | server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1 |
| 139 | |
Christopher Faulet | b381a50 | 2020-11-25 13:47:00 +0100 | [diff] [blame] | 140 | backend be5 |
| 141 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 142 | option httpchk |
| 143 | server srv ${h1_li1_addr}:${h1_li1_port} proto h2 check inter 100ms rise 1 fall 1 |
| 144 | |
| 145 | backend be6 |
| 146 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 147 | option httpchk GET /status HTTP/1.1 |
| 148 | server srv ${h1_li1_addr}:${h1_li1_port} check check-proto h2 inter 100ms rise 1 fall 1 |
| 149 | |
| 150 | listen li1 |
| 151 | mode http |
| 152 | bind "fd@${li1}" proto h2 |
| 153 | http-request return status 200 |
| 154 | |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 155 | } -start |
| 156 | |
| 157 | syslog S1 -wait |