summaryrefslogtreecommitdiffstats
path: root/reg-tests/checks/http-check.vtc
blob: 335306075c4fc22f4de765ff2ba4bfc0326c4803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
varnishtest "Health-checks: some http-check tests"
feature ignore_unknown_macro
#REQUIRE_VERSION=2.2
#REGTEST_TYPE=slow
# This script tests HTTP health-checks.

server s1 {
    rxreq
    expect req.method == OPTIONS
    expect req.url == /
    expect req.proto == HTTP/1.0
    txresp
} -start

server s2 {
    rxreq
    expect req.method == GET
    expect req.url == /status
    expect req.proto == HTTP/1.1
    txresp
} -start

server s3 {
    rxreq
    expect req.method == GET
    expect req.url == /status
    expect req.proto == HTTP/1.1
    txresp
} -start

server s4 {
    rxreq
    expect req.method == GET
    expect req.url == /req1
    expect req.proto == HTTP/1.1
    expect req.http.x-test == "server=srv"
    expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv"
    expect req.bodylen == 0
    txresp

    accept
    rxreq
    expect req.method == GET
    expect req.url == /req2
    expect req.proto == HTTP/1.1
    expect req.http.x-test == "server="
    expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv"
    expect req.http.content-length == 17
    expect req.bodylen == 17
    expect req.body == "health-check body"
    txresp

    accept
    rxreq
    expect req.method == GET
    expect req.url == /req3
    expect req.proto == HTTP/1.0
    expect req.http.x-test == <undef>
    expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv"
    expect req.bodylen == 0
    txresp

    accept
    rxreq
    expect req.method == GET
    expect req.url == /
    expect req.proto == HTTP/1.0
    expect req.http.x-test == <undef>
    expect req.http.x-haproxy-server-state ~ "UP.+name=be4/srv"
    expect req.bodylen == 23
    expect req.body == "health-check on be4-srv"
    txresp

} -start

syslog S1 -level notice {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be[0-9]/srv succeeded.*code: 200"
} -start

haproxy h1 -conf {
    defaults
        mode http
        timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
        option log-health-checks

    backend be1
        log ${S1_addr}:${S1_port} len 2048 local0
        option httpchk
        server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1

    backend be2
        log ${S1_addr}:${S1_port} len 2048 local0
        option httpchk GET /status HTTP/1.1
        server srv ${s2_addr}:${s2_port} check inter 100ms rise 1 fall 1

    backend be3
        log ${S1_addr}:${S1_port} len 2048 local0
        option httpchk
        http-check send meth GET uri /status ver HTTP/1.1
        server srv ${s3_addr}:${s3_port} check inter 100ms rise 1 fall 1

    backend be4
        mode tcp
        log ${S1_addr}:${S1_port} len 2048 local0
        option httpchk
        http-check send-state
        http-check connect addr ${s4_addr}:${s4_port}
        http-check set-var(check.server) "str(srv)"
        http-check set-var(check.path) "str(/req1)"
        http-check send meth GET uri-lf "%[var(check.path)]" ver HTTP/1.1 hdr x-test "server=%[var(check.server)]"
        http-check expect status 200
        http-check connect addr ${s4_addr} port ${s4_port}
        http-check unset-var(check.server)
        http-check set-var(check.path) "str(/req2)"
        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"
        http-check expect rstatus "^2[0-9]{2}"
        http-check connect addr ${s4_addr} port ${s4_port}
        http-check set-var(check.path) "str(/req3)"
        http-check send meth GET uri-lf "%[var(check.path)]"
        http-check expect rstatus "^2[0-9]{2}"
        http-check connect addr ${s4_addr} port ${s4_port}
        http-check unset-var(check.path)
        http-check send meth GET uri-lf "%[var(check.path)]" body-lf "health-check on %[be_name]-%[srv_name]"
        ## implicit expect rule
        server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1

    backend be5
        log ${S1_addr}:${S1_port} len 2048 local0
        option httpchk
        server srv ${h1_li1_addr}:${h1_li1_port} proto h2 check inter 100ms rise 1 fall 1

    backend be6
        log ${S1_addr}:${S1_port} len 2048 local0
        option httpchk GET /status HTTP/1.1
        server srv ${h1_li1_addr}:${h1_li1_port} check check-proto h2 inter 100ms rise 1 fall 1

    listen li1
        mode http
        bind "fd@${li1}" proto h2
        http-request return status 200

} -start

syslog S1 -wait