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 | |
| 63 | } -start |
| 64 | |
| 65 | syslog S1 -level notice { |
| 66 | recv |
| 67 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started." |
| 68 | recv |
| 69 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started." |
| 70 | recv |
| 71 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started." |
| 72 | recv |
| 73 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started." |
| 74 | |
| 75 | recv |
| 76 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200" |
| 77 | recv |
| 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 | } -start |
| 84 | |
| 85 | haproxy h1 -conf { |
| 86 | defaults |
| 87 | mode http |
| 88 | timeout client 1s |
| 89 | timeout server 1s |
| 90 | timeout connect 100ms |
| 91 | option log-health-checks |
| 92 | |
| 93 | backend be1 |
| 94 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 95 | option httpchk |
| 96 | server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1 |
| 97 | |
| 98 | backend be2 |
| 99 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 100 | option httpchk GET /status HTTP/1.1 |
| 101 | server srv ${s2_addr}:${s2_port} check inter 100ms rise 1 fall 1 |
| 102 | |
| 103 | backend be3 |
| 104 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 105 | option httpchk |
| 106 | http-check send meth GET uri /status vsn HTTP/1.1 |
| 107 | server srv ${s3_addr}:${s3_port} check inter 100ms rise 1 fall 1 |
| 108 | |
| 109 | backend be4 |
| 110 | mode tcp |
| 111 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 112 | option httpchk |
| 113 | http-check send-state |
| 114 | http-check connect addr ${s4_addr}:${s4_port} |
| 115 | http-check set-var(check.server) "str(srv)" |
| 116 | http-check send meth GET uri /req1 vsn HTTP/1.1 hdr x-test "server=%[var(check.server)]" |
| 117 | http-check expect status 200 |
| 118 | http-check connect addr ${s4_addr} port ${s4_port} |
| 119 | http-check unset-var(check.server) |
| 120 | http-check send meth GET uri /req2 vsn HTTP/1.1 hdr x-test "server=%[var(check.server)]" body "health-check body" |
| 121 | http-check expect rstatus "^2[0-9]{2}" |
| 122 | http-check connect addr ${s4_addr} port ${s4_port} |
| 123 | http-check send meth GET uri /req3 |
| 124 | ## implicit expect rule |
| 125 | server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1 |
| 126 | |
| 127 | } -start |
| 128 | |
| 129 | syslog S1 -wait |