blob: 4620d6fd7411a1b044505df2c1912f4e607d6f1b [file] [log] [blame]
Christopher Fauletaec7f762020-04-22 15:16:58 +02001varnishtest "Health-checks: PostgreSQL health-check"
2#REQUIRE_VERSION=2.2
3#REGTEST_TYPE=slow
4feature ignore_unknown_macro
5
6# This scripts tests health-checks for PostgreSQL application, enabled using
7# "option pgsql-check" line. A intermediate listener is used to validate
8# the request because it is impossible with VTEST to read and match raw
9# text.
10
11server s1 {
12 recv 23
13 sendhex "520000000800000000"
14} -start
15
16server s2 {
17 recv 23
18 sendhex "450000000B53464154414C00"
19} -start
20
21server s3 {
22 recv 23
23 send "Not a PostgreSQL response"
24} -start
25
26syslog S1 -level notice {
27 recv
28 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be1 started."
29 recv
30 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv succeeded, reason: Layer7 check passed.+info: \"PostgreSQL server is ok\".+check duration: [[:digit:]]+ms, status: 1/1 UP."
31} -start
32
33syslog S2 -level notice {
34 recv
35 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be2 started."
36 recv
37 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv failed, reason: Layer7 invalid response.+info: \"FATAL\".+check duration: [[:digit:]]+ms, status: 0/1 DOWN."
38} -start
39
40syslog S3 -level notice {
41 recv
42 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be3 started."
43 recv
44 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be3/srv failed, reason: Layer7 wrong status.+info: \"PostgreSQL unknown error\".+check duration: [[:digit:]]+ms, status: 0/1 DOWN."
45} -start
46
47
48haproxy h1 -conf {
49 defaults
50 mode tcp
51 timeout client 1s
52 timeout server 1s
53 timeout connect 100ms
54
55 backend be1
56 log ${S1_addr}:${S1_port} daemon
57 option log-health-checks
58 option pgsql-check user postgres
59 server srv ${h1_pgsql_addr}:${h1_pgsql_port} check inter 1s rise 1 fall 1
60
61 backend be2
62 log ${S2_addr}:${S2_port} daemon
63 option log-health-checks
64 option pgsql-check user postgres
65 server srv ${s2_addr}:${s2_port} check inter 1s rise 1 fall 1
66
67 backend be3
68 log ${S3_addr}:${S3_port} daemon
69 option log-health-checks
70 option pgsql-check user postgres
71 server srv ${s3_addr}:${s3_port} check inter 1s rise 1 fall 1
72
73 listen pgsql1
74 bind "fd@${pgsql}"
75 tcp-request inspect-delay 100ms
76 tcp-request content accept if { req.len eq 23 } { req.payload(0,23) -m bin "00000017000300007573657200706f7374677265730000" }
77 tcp-request content reject
78 server srv ${s1_addr}:${s1_port}
79} -start
80
81syslog S1 -wait
82syslog S2 -wait
83syslog S3 -wait