Changed subject of patch requirement to 'REGTEST'.
Op 23-12-2018 om 21:17 schreef PiBa-NL:
Hi List,
Attached a new test to verify that the 'mailers' section is working
properly.
Currently with 1.9 the mailers sends thousands of mails for my setup...
As the test is rather slow i have marked it with a starting letter 's'.
Note that the test also fails on 1.6/1.7/1.8 but can be 'fixed' there
by adding a 'timeout mail 200ms'.. (except on 1.6 which doesn't have
that setting.)
I don't think that should be needed though if everything was working
properly?
If the test could be committed, and related issues exposed fixed that
would be neat ;)
Thanks in advance,
PiBa-NL (Pieter)
From 8d63f5a39a9b4b326b636e42ccafcf0c2173d752 Mon Sep 17 00:00:00 2001
From: PiBa-NL <piba.nl....@gmail.com>
Date: Sun, 23 Dec 2018 21:06:31 +0100
Subject: [PATCH] REGTEST: mailers: add new test for 'mailers' section
This test verifies the mailers section works properly by checking that it sends
the proper amount of mails when health-checks are changing and or marking a
server up/down
The test currently fails on all versions of haproxy i tried with varying
results.
1.9.0 produces thousands of mails..
1.8.14 only sends 1 mail, needs a 200ms 'timeout mail' to succeed
1.7.11 only sends 1 mail, needs a 200ms 'timeout mail' to succeed
1.6 only sends 1 mail, (does not have the 'timeout mail' setting implemented)
---
reg-tests/mailers/shealthcheckmail.lua | 105 +++++++++++++++++++++++++
reg-tests/mailers/shealthcheckmail.vtc | 75 ++++++++++++++++++
2 files changed, 180 insertions(+)
create mode 100644 reg-tests/mailers/shealthcheckmail.lua
create mode 100644 reg-tests/mailers/shealthcheckmail.vtc
diff --git a/reg-tests/mailers/shealthcheckmail.lua
b/reg-tests/mailers/shealthcheckmail.lua
new file mode 100644
index 00000000..9c75877b
--- /dev/null
+++ b/reg-tests/mailers/shealthcheckmail.lua
@@ -0,0 +1,105 @@
+
+local vtc_port1 = 0
+local mailsreceived = 0
+local mailconnectionsmade = 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)
+ data = applet:getline()
+ if data:sub(1,expect:len()) ~= expect then
+ core.Info("Expected: "..expect.." but
got:"..data:sub(1,expect:len()))
+ applet:send("Expected: "..expect.." but got:"..data.."\r\n")
+ return false
+ end
+ return true
+end
+
+core.register_service("mailservice", "tcp", function(applet)
+ core.Info("############# Mailservice Called #############")
+ mailconnectionsmade = mailconnectionsmade + 1
+ applet:send("220 Welcome\r\n")
+ local data
+
+ if RecieveAndCheck(applet, "EHLO") == false then
+ return
+ end
+ applet:send("250 OK\r\n")
+ if RecieveAndCheck(applet, "MAIL FROM:") == false then
+ return
+ end
+ applet:send("250 OK\r\n")
+ if RecieveAndCheck(applet, "RCPT TO:") == false then
+ return
+ end
+ applet:send("250 OK\r\n")
+ if RecieveAndCheck(applet, "DATA") == false then
+ return
+ end
+ applet:send("354 OK\r\n")
+ core.Info("#### Send your mailbody")
+ local endofmail = false
+ local subject = ""
+ while endofmail ~= true do
+ data = applet:getline() -- BODY CONTENT
+ --core.Info(data)
+ if data:sub(1, 9) == "Subject: " then
+ subject = data
+ end
+ if (data == "\r\n") then
+ data = applet:getline() -- BODY CONTENT
+ core.Info(data)
+ if (data == ".\r\n") then
+ endofmail = true
+ end
+ end
+ end
+ core.Info("#### Body recieved OK")
+ applet:send("250 OK\r\n")
+
+ if RecieveAndCheck(applet, "QUIT") == false then
+ return
+ end
+ applet:send("221 Mail queued for delivery to /dev/null \r\n")
+ core.Info("Mail queued for delivery to /dev/null subject: "..subject)
+ mailsreceived = mailsreceived + 1
+end)
diff --git a/reg-tests/mailers/shealthcheckmail.vtc
b/reg-tests/mailers/shealthcheckmail.vtc
new file mode 100644
index 00000000..5fcbf52c
--- /dev/null
+++ b/reg-tests/mailers/shealthcheckmail.vtc
@@ -0,0 +1,75 @@
+varnishtest "Lua: txn:get_priv() scope"
+#REQUIRE_OPTIONS=LUA
+#REQUIRE_VERSION=1.6
+
+feature ignore_unknown_macro
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+haproxy h1 -conf {
+ global
+ lua-load ${testdir}/shealthcheckmail.lua
+defaults
+ frontend femail
+ mode tcp
+ bind "fd@${femail}"
+ tcp-request content use-service lua.mailservice
+
+ frontend luahttpservice
+ mode http
+ bind "fd@${luahttpservice}"
+ http-request use-service lua.luahttpservice
+
+ frontend fe1
+ mode http
+ bind "fd@${fe1}"
+ default_backend b1
+
+ http-response lua.bug
+
+ backend b1
+ mode http
+ option httpchk /svr_healthcheck
+ option log-health-checks
+
+ email-alert mailers mymailers
+ email-alert level info
+ email-alert from f...@domain.tld
+ email-alert to t...@domain.tld
+
+ server broken 127.0.0.1:65535 check
+ server srv_lua ${h1_luahttpservice_addr}:${h1_luahttpservice_port}
check inter 500
+ server srv1 ${s1_addr}:${s1_port} check inter 500
+
+ mailers mymailers
+# timeout mail 20s
+# timeout mail 200ms
+ mailer smtp1 ipv6@${h1_femail_addr}:${h1_femail_port}
+
+} -start
+
+# configure port for lua to call feluaservice
+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
--
2.18.0.windows.1