blob: 3de3e3f8fe98430e5a13b5ac4d4672e0238ebdb5 [file] [log] [blame]
Christopher Fauletaec7f762020-04-22 15:16:58 +02001varnishtest "Health-checks: some http-check tests"
2feature ignore_unknown_macro
3#REQUIRE_VERSION=2.2
4#REGTEST_TYPE=slow
5# This script tests HTTP health-checks.
6
7server s1 {
8 rxreq
9 expect req.method == OPTIONS
10 expect req.url == /
11 expect req.proto == HTTP/1.0
12 txresp
13} -start
14
15server 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
23server 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
31server 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 Faulet7c95f5f2020-05-06 15:06:34 +020063 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"
70 expect req.bodylen == 0
71 txresp
72
Christopher Fauletaec7f762020-04-22 15:16:58 +020073} -start
74
75syslog S1 -level notice {
76 recv
77 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started."
78 recv
79 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started."
80 recv
81 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started."
82 recv
83 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be[0-9]+ started."
84
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"
89 recv
90 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
91 recv
92 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
93} -start
94
95haproxy h1 -conf {
96 defaults
97 mode http
98 timeout client 1s
99 timeout server 1s
100 timeout connect 100ms
101 option log-health-checks
102
103 backend be1
104 log ${S1_addr}:${S1_port} len 2048 local0
105 option httpchk
106 server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1
107
108 backend be2
109 log ${S1_addr}:${S1_port} len 2048 local0
110 option httpchk GET /status HTTP/1.1
111 server srv ${s2_addr}:${s2_port} check inter 100ms rise 1 fall 1
112
113 backend be3
114 log ${S1_addr}:${S1_port} len 2048 local0
115 option httpchk
Christopher Faulet907701b2020-04-28 09:37:00 +0200116 http-check send meth GET uri /status ver HTTP/1.1
Christopher Fauletaec7f762020-04-22 15:16:58 +0200117 server srv ${s3_addr}:${s3_port} check inter 100ms rise 1 fall 1
118
119 backend be4
120 mode tcp
121 log ${S1_addr}:${S1_port} len 2048 local0
122 option httpchk
123 http-check send-state
124 http-check connect addr ${s4_addr}:${s4_port}
125 http-check set-var(check.server) "str(srv)"
Christopher Faulet7c95f5f2020-05-06 15:06:34 +0200126 http-check set-var(check.path) "str(/req1)"
127 http-check send meth GET uri-lf "%[var(check.path)]" ver HTTP/1.1 hdr x-test "server=%[var(check.server)]"
Christopher Fauletaec7f762020-04-22 15:16:58 +0200128 http-check expect status 200
129 http-check connect addr ${s4_addr} port ${s4_port}
130 http-check unset-var(check.server)
Christopher Faulet7c95f5f2020-05-06 15:06:34 +0200131 http-check set-var(check.path) "str(/req2)"
132 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"
133 http-check expect rstatus "^2[0-9]{2}"
134 http-check connect addr ${s4_addr} port ${s4_port}
135 http-check set-var(check.path) "str(/req3)"
136 http-check send meth GET uri-lf "%[var(check.path)]"
Christopher Fauletaec7f762020-04-22 15:16:58 +0200137 http-check expect rstatus "^2[0-9]{2}"
138 http-check connect addr ${s4_addr} port ${s4_port}
Christopher Faulet7c95f5f2020-05-06 15:06:34 +0200139 http-check unset-var(check.path)
140 http-check send meth GET uri-lf "%[var(check.path)]" # default to "/"
Christopher Fauletaec7f762020-04-22 15:16:58 +0200141 ## implicit expect rule
142 server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1
143
144} -start
145
146syslog S1 -wait