mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 23:27:04 +02:00
REGTESTS: healthcheckmail: Update the test to be functionnal again
This reg-test is broken since a while. It was simplified to be functionnal. Now, it only test email alerts.
This commit is contained in:
parent
58e3501910
commit
52912579ee
@ -4,46 +4,6 @@ local mailsreceived = 0
|
|||||||
local mailconnectionsmade = 0
|
local mailconnectionsmade = 0
|
||||||
local healthcheckcounter = 0
|
local healthcheckcounter = 0
|
||||||
|
|
||||||
core.register_action("bug", { "http-res" }, function(txn)
|
|
||||||
data = txn:get_priv()
|
|
||||||
if not data then
|
|
||||||
data = 0
|
|
||||||
end
|
|
||||||
data = data + 1
|
|
||||||
print(string.format("set to %d", data))
|
|
||||||
txn.http:res_set_status(200 + data)
|
|
||||||
txn:set_priv(data)
|
|
||||||
end)
|
|
||||||
|
|
||||||
core.register_service("luahttpservice", "http", function(applet)
|
|
||||||
local response = "?"
|
|
||||||
local responsestatus = 200
|
|
||||||
if applet.path == "/setport" then
|
|
||||||
vtc_port1 = applet.headers["vtcport1"][0]
|
|
||||||
response = "OK"
|
|
||||||
end
|
|
||||||
if applet.path == "/svr_healthcheck" then
|
|
||||||
healthcheckcounter = healthcheckcounter + 1
|
|
||||||
if healthcheckcounter < 2 or healthcheckcounter > 6 then
|
|
||||||
responsestatus = 403
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
applet:set_status(responsestatus)
|
|
||||||
if applet.path == "/checkMailCounters" then
|
|
||||||
response = "MailCounters"
|
|
||||||
applet:add_header("mailsreceived", mailsreceived)
|
|
||||||
applet:add_header("mailconnectionsmade", mailconnectionsmade)
|
|
||||||
end
|
|
||||||
applet:start_response()
|
|
||||||
applet:send(response)
|
|
||||||
end)
|
|
||||||
|
|
||||||
core.register_service("fakeserv", "http", function(applet)
|
|
||||||
applet:set_status(200)
|
|
||||||
applet:start_response()
|
|
||||||
end)
|
|
||||||
|
|
||||||
function RecieveAndCheck(applet, expect)
|
function RecieveAndCheck(applet, expect)
|
||||||
data = applet:getline()
|
data = applet:getline()
|
||||||
if data:sub(1,expect:len()) ~= expect then
|
if data:sub(1,expect:len()) ~= expect then
|
||||||
@ -60,19 +20,23 @@ core.register_service("mailservice", "tcp", function(applet)
|
|||||||
applet:send("220 Welcome\r\n")
|
applet:send("220 Welcome\r\n")
|
||||||
local data
|
local data
|
||||||
|
|
||||||
if RecieveAndCheck(applet, "EHLO") == false then
|
if RecieveAndCheck(applet, "HELO") == false then
|
||||||
|
applet:set_var("txn.result", "ERROR (step: HELO)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
applet:send("250 OK\r\n")
|
applet:send("250 OK\r\n")
|
||||||
if RecieveAndCheck(applet, "MAIL FROM:") == false then
|
if RecieveAndCheck(applet, "MAIL FROM:") == false then
|
||||||
|
applet:set_var("txn.result", "ERROR (step: MAIL FROM)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
applet:send("250 OK\r\n")
|
applet:send("250 OK\r\n")
|
||||||
if RecieveAndCheck(applet, "RCPT TO:") == false then
|
if RecieveAndCheck(applet, "RCPT TO:") == false then
|
||||||
|
applet:set_var("txn.result", "ERROR (step: RCPT TO)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
applet:send("250 OK\r\n")
|
applet:send("250 OK\r\n")
|
||||||
if RecieveAndCheck(applet, "DATA") == false then
|
if RecieveAndCheck(applet, "DATA") == false then
|
||||||
|
applet:set_var("txn.result", "ERROR (step: DATA)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
applet:send("354 OK\r\n")
|
applet:send("354 OK\r\n")
|
||||||
@ -97,9 +61,10 @@ core.register_service("mailservice", "tcp", function(applet)
|
|||||||
applet:send("250 OK\r\n")
|
applet:send("250 OK\r\n")
|
||||||
|
|
||||||
if RecieveAndCheck(applet, "QUIT") == false then
|
if RecieveAndCheck(applet, "QUIT") == false then
|
||||||
|
applet:set_var("txn.result", "ERROR (step: QUIT)")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
applet:send("221 Mail queued for delivery to /dev/null \r\n")
|
applet:send("221 Mail queued for delivery to /dev/null \r\n")
|
||||||
core.Info("Mail queued for delivery to /dev/null subject: "..subject)
|
core.Info("Mail queued for delivery to /dev/null subject: "..subject)
|
||||||
mailsreceived = mailsreceived + 1
|
applet:set_var("txn.result", "SUCCESS")
|
||||||
end)
|
end)
|
||||||
|
@ -1,75 +1,59 @@
|
|||||||
varnishtest "Lua: txn:get_priv() scope"
|
varnishtest "Check health-check email alerts"
|
||||||
#REQUIRE_OPTIONS=LUA
|
#REQUIRE_OPTIONS=LUA
|
||||||
#REGTEST_TYPE=broken
|
|
||||||
|
|
||||||
feature ignore_unknown_macro
|
feature ignore_unknown_macro
|
||||||
|
|
||||||
server s1 {
|
syslog S1 -level notice {
|
||||||
rxreq
|
recv
|
||||||
txresp
|
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 failed.+reason: Socket error.+info: \"Connection reset by peer\".+check duration: [[:digit:]]+ms.+status: 0/1 DOWN."
|
||||||
|
recv info
|
||||||
|
expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Result=SUCCESS Bytes=[[:digit:]]+"
|
||||||
} -start
|
} -start
|
||||||
|
|
||||||
haproxy h1 -conf {
|
haproxy h1 -conf {
|
||||||
global
|
global
|
||||||
lua-load ${testdir}/healthcheckmail.lua
|
lua-load ${testdir}/healthcheckmail.lua
|
||||||
defaults
|
|
||||||
frontend femail
|
|
||||||
mode tcp
|
|
||||||
bind "fd@${femail}"
|
|
||||||
tcp-request content use-service lua.mailservice
|
|
||||||
|
|
||||||
frontend luahttpservice
|
defaults
|
||||||
mode http
|
timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
|
||||||
bind "fd@${luahttpservice}"
|
timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
|
||||||
http-request use-service lua.luahttpservice
|
timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
|
||||||
|
|
||||||
|
listen lisrv
|
||||||
|
mode tcp
|
||||||
|
bind "fd@${lisrv}"
|
||||||
|
tcp-request connection reject
|
||||||
|
|
||||||
|
listen lismtp
|
||||||
|
mode tcp
|
||||||
|
bind "fd@${lismtp}"
|
||||||
|
log ${S1_addr}:${S1_port} daemon
|
||||||
|
log-format "Result=%[var(txn.result)] Bytes=%B"
|
||||||
|
tcp-request content use-service lua.mailservice
|
||||||
|
|
||||||
frontend fe1
|
frontend fe1
|
||||||
mode http
|
mode http
|
||||||
bind "fd@${fe1}"
|
bind "fd@${fe1}"
|
||||||
default_backend b1
|
default_backend be1
|
||||||
|
|
||||||
http-response lua.bug
|
backend be1
|
||||||
|
|
||||||
backend b1
|
|
||||||
mode http
|
mode http
|
||||||
option httpchk /svr_healthcheck
|
log ${S1_addr}:${S1_port} daemon
|
||||||
|
option httpchk
|
||||||
option log-health-checks
|
option log-health-checks
|
||||||
|
|
||||||
|
default-server inter 200ms downinter 100ms rise 1 fall 1
|
||||||
|
|
||||||
email-alert mailers mymailers
|
email-alert mailers mymailers
|
||||||
email-alert level info
|
email-alert level info
|
||||||
email-alert from from@domain.tld
|
email-alert from from@domain.tld
|
||||||
email-alert to to@domain.tld
|
email-alert to to@domain.tld
|
||||||
|
|
||||||
server broken 127.0.0.1:65535 check
|
server srv1 ${h1_lisrv_addr}:${h1_lisrv_port} check
|
||||||
server srv_lua ${h1_luahttpservice_addr}:${h1_luahttpservice_port} check inter 500
|
|
||||||
server srv1 ${s1_addr}:${s1_port} check inter 500
|
|
||||||
|
|
||||||
mailers mymailers
|
mailers mymailers
|
||||||
# timeout mail 20s
|
mailer smtp1 ${h1_lismtp_addr}:${h1_lismtp_port}
|
||||||
# timeout mail 200ms
|
|
||||||
mailer smtp1 ${h1_femail_addr}:${h1_femail_port}
|
|
||||||
|
|
||||||
} -start
|
} -start
|
||||||
|
|
||||||
# configure port for lua to call feluaservice
|
syslog S1 -wait
|
||||||
client c1 -connect ${h1_luahttpservice_sock} {
|
|
||||||
timeout 2
|
|
||||||
txreq -url "/setport" -hdr "vtcport1: ${h1_femail_port}"
|
|
||||||
rxresp
|
|
||||||
expect resp.status == 200
|
|
||||||
expect resp.body == "OK"
|
|
||||||
} -run
|
|
||||||
|
|
||||||
delay 2
|
|
||||||
server s2 -repeat 5 -start
|
|
||||||
delay 5
|
|
||||||
|
|
||||||
client c2 -connect ${h1_luahttpservice_sock} {
|
|
||||||
timeout 2
|
|
||||||
txreq -url "/checkMailCounters"
|
|
||||||
rxresp
|
|
||||||
expect resp.status == 200
|
|
||||||
expect resp.body == "MailCounters"
|
|
||||||
expect resp.http.mailsreceived == 16
|
|
||||||
expect resp.http.mailconnectionsmade == 16
|
|
||||||
} -run
|
|
||||||
|
Loading…
Reference in New Issue
Block a user