blob: 530ad75669e20584f452d497e9aa7b8d72758683 [file] [log] [blame]
Christopher Faulet8acb1282020-04-09 08:44:06 +02001varnishtest "Health-checks: http-check send test"
Christopher Fauletaec7f762020-04-22 15:16:58 +02002#REGTEST_TYPE=slow
Willy Tarreaucb4ed022021-02-04 18:06:13 +01003#REQUIRE_VERSION=2.4
Christopher Faulet8acb1282020-04-09 08:44:06 +02004feature ignore_unknown_macro
5
6# This script tests HTTP health-checks and more particularly the "http-check
7# send" directive.
8
9server s1 {
10 rxreq
11 expect req.method == OPTIONS
12 expect req.url == /
13 expect req.proto == HTTP/1.0
14 txresp
15} -start
16
17server s2 {
18 rxreq
19 expect req.method == GET
20 expect req.url == /test
21 expect req.proto == HTTP/1.1
Willy Tarreau2da74292021-02-05 10:13:15 +010022 expect req.http.connection == "close"
Christopher Faulet8acb1282020-04-09 08:44:06 +020023 txresp
24} -start
25
26server s3 {
27 rxreq
28 expect req.method == OPTIONS
29 expect req.url == /
30 expect req.proto == HTTP/1.0
Christopher Faulet8acb1282020-04-09 08:44:06 +020031 expect req.http.host == <undef>
32 expect req.http.x-test == <undef>
Christopher Faulet8acb1282020-04-09 08:44:06 +020033 expect req.bodylen == 0
34 txresp
35} -start
36
37server s4 {
38 rxreq
39 expect req.method == GET
40 expect req.url == /status
41 expect req.proto == HTTP/1.1
Willy Tarreau2da74292021-02-05 10:13:15 +010042 expect req.http.connection == "close"
Christopher Faulet8acb1282020-04-09 08:44:06 +020043 expect req.http.host == "my-www-host"
44 expect req.http.x-test == true
45 expect req.http.content-length == 4
46 expect req.bodylen == 4
47 expect req.body == "test"
48 txresp
49} -start
50
51server s5 {
52 rxreq
Christopher Fauleta67ed432020-04-20 14:59:20 +020053 expect req.method == OPTIONS
54 expect req.url == /
55 expect req.proto == HTTP/1.0
Christopher Faulet8acb1282020-04-09 08:44:06 +020056 expect req.http.host == "other-www-host"
57 expect req.http.x-test == <undef>
58 expect req.http.x-new-test == true
59 expect req.http.content-length == 10
60 expect req.bodylen == 10
61 expect req.body == "other test"
62 txresp
63} -start
64
Willy Tarreau2da74292021-02-05 10:13:15 +010065server s6 {
66 rxreq
67 expect req.method == GET
68 expect req.url == /
69 expect req.proto == HTTP/1.1
70 expect req.http.host == "ws-host"
71 expect req.http.connection == "upgrade"
72 expect req.http.upgrade == "raw-proto"
73 txresp \
74 -status 101 \
75 -hdr "connection: upgrade" \
76 -hdr "upgrade: raw-proto"
77} -start
78
Christopher Faulet8acb1282020-04-09 08:44:06 +020079
80syslog S1 -level notice {
81 recv
Christopher Faulet8acb1282020-04-09 08:44:06 +020082 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv succeeded.*code: 200"
83} -start
84
85syslog S2 -level notice {
86 recv
Christopher Faulet8acb1282020-04-09 08:44:06 +020087 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv succeeded.*code: 200"
88} -start
89
90syslog S3 -level notice {
91 recv
Christopher Faulet8acb1282020-04-09 08:44:06 +020092 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be3/srv succeeded.*code: 200"
93} -start
94
95syslog S4 -level notice {
96 recv
Christopher Faulet8acb1282020-04-09 08:44:06 +020097 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be4/srv succeeded.*code: 200"
98} -start
99
100syslog S5 -level notice {
101 recv
Christopher Faulet8acb1282020-04-09 08:44:06 +0200102 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be5/srv succeeded.*code: 200"
103} -start
104
Willy Tarreau2da74292021-02-05 10:13:15 +0100105syslog S6 -level notice {
106 recv
107 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be6_ws/srv succeeded.*code: 101"
108} -start
109
Christopher Faulet8acb1282020-04-09 08:44:06 +0200110
111haproxy h1 -conf {
112 defaults
113 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +0100114 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
115 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
116 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
Christopher Faulet8acb1282020-04-09 08:44:06 +0200117 option httpchk
118 option log-health-checks
119
120 backend be1
121 log ${S1_addr}:${S1_port} len 2048 local0
122 server srv ${s1_addr}:${s1_port} check inter 200ms rise 1 fall 1
123
124 backend be2
125 log ${S2_addr}:${S2_port} len 2048 local0
126 option httpchk GET /test HTTP/1.1
127 server srv ${s2_addr}:${s2_port} check inter 200ms rise 1 fall 1
128
129 defaults
130 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +0100131 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
132 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
133 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
Christopher Faulet4b5f3022022-09-05 09:05:17 +0200134 option httpchk GET /status HTTP/1.1
Christopher Faulet8acb1282020-04-09 08:44:06 +0200135 option log-health-checks
136 http-check send hdr Host "my-www-host" hdr X-test true body "test"
137
138 backend be3
139 option httpchk
140 log ${S3_addr}:${S3_port} len 2048 local0
141 server srv ${s3_addr}:${s3_port} check inter 200ms rise 1 fall 1
142
143 backend be4
144 log ${S4_addr}:${S4_port} len 2048 local0
145 server srv ${s4_addr}:${s4_port} check inter 200ms rise 1 fall 1
146
147 backend be5
148 log ${S5_addr}:${S5_port} len 2058 local0
149 http-check send hdr Host "other-www-host" hdr X-New-Test true body "other test"
150 server srv ${s5_addr}:${s5_port} check inter 200ms rise 1 fall 1
151
Willy Tarreau2da74292021-02-05 10:13:15 +0100152 backend be6_ws
153 log ${S6_addr}:${S6_port} len 2048 local0
154 http-check send meth GET uri / ver HTTP/1.1 hdr host ws-host hdr connection upgrade hdr upgrade raw-proto
155 http-check expect status 101
156 server srv ${s6_addr}:${s6_port} check inter 200ms rise 1 fall 1
157
Christopher Faulet8acb1282020-04-09 08:44:06 +0200158} -start
159
160syslog S1 -wait
161syslog S2 -wait
162syslog S3 -wait
163syslog S4 -wait
164syslog S5 -wait
Willy Tarreau2da74292021-02-05 10:13:15 +0100165syslog S6 -wait