summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-09-11 11:04:25 +0100
committerGitHub <noreply@github.com>2018-09-11 11:04:25 +0100
commit36aac959a763a1fdd82b9056b43962d4ea898e38 (patch)
tree9ee7a350d6cb3a401f12f28cd921129009aba1e5
parent4beacdc68099d3578744fec07502ddae7b4a4c6b (diff)
parent352bf6f96a93599883eaeb5954c09d01181d83e7 (diff)
downloadrspamd-36aac959a763a1fdd82b9056b43962d4ea898e38.tar.gz
rspamd-36aac959a763a1fdd82b9056b43962d4ea898e38.zip
Merge pull request #2478 from negram/down-tcp-test-case
[Test] Added test case for error handling check
-rw-r--r--test/functional/cases/231_tcp_down.robot41
-rw-r--r--test/functional/lua/tcp.lua7
2 files changed, 47 insertions, 1 deletions
diff --git a/test/functional/cases/231_tcp_down.robot b/test/functional/cases/231_tcp_down.robot
new file mode 100644
index 000000000..474faa3f5
--- /dev/null
+++ b/test/functional/cases/231_tcp_down.robot
@@ -0,0 +1,41 @@
+*** Settings ***
+Test Setup Http Setup
+Test Teardown Http Teardown
+Library Process
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+# ${CONFIG} ${TESTDIR}/configs/http.conf
+${URL_TLD} ${TESTDIR}/../lua/unit/test_tld.dat
+${CONFIG} ${TESTDIR}/configs/lua_test.conf
+${MESSAGE} ${TESTDIR}/messages/spam_message.eml
+${RSPAMD_SCOPE} Test
+
+*** Test Cases ***
+
+Sync API TCP get request when server is down
+ [Documentation] We don't create HTTP server here, that's why
+ ... all requests fail with "connection refused"
+ Check url /request get HTTP_ASYNC_RESPONSE (0.00)[Socket error detected: Connection refused]
+ Check url /content-length HTTP_SYNC_WRITE_ERROR (0.00)[Socket error detected: Connection refused]
+
+
+*** Keywords ***
+Lua Setup
+ [Arguments] ${LUA_SCRIPT}
+ Set Global Variable ${LUA_SCRIPT}
+ Generic Setup
+
+Http Setup
+ Lua Setup ${TESTDIR}/lua/tcp.lua
+
+Http Teardown
+ Normal Teardown
+
+Check url
+ [Arguments] ${url} ${method} @{expect_results}
+ ${result} = Scan Message With Rspamc --header=url:${url} --header=method:${method} ${MESSAGE}
+ : FOR ${expect} IN @{expect_results}
+ \ Check Rspamc ${result} ${expect}
diff --git a/test/functional/lua/tcp.lua b/test/functional/lua/tcp.lua
index 21bb0c6e7..30285c4f5 100644
--- a/test/functional/lua/tcp.lua
+++ b/test/functional/lua/tcp.lua
@@ -20,7 +20,7 @@ local function http_simple_tcp_async_symbol(task)
local function http_read_cb(err, data, conn)
logger.errx(task, 'http_read_cb: got reply: %s, error: %s, conn: %s', data, err, conn)
conn:add_write(http_read_post_cb, "POST /request2 HTTP/1.1\r\n\r\n")
- task:insert_result('HTTP_ASYNC_RESPONSE', 1.0, data)
+ task:insert_result('HTTP_ASYNC_RESPONSE', 1.0, data or err)
end
rspamd_tcp:request({
task = task,
@@ -43,6 +43,11 @@ local function http_simple_tcp_symbol(task)
port = 18080,
}
+ if not is_ok then
+ task:insert_result('HTTP_SYNC_WRITE_ERROR', 1.0, connection)
+ logger.errx(task, 'write error: %1', connection)
+ end
+
logger.errx(task, 'connect_sync %1, %2', is_ok, tostring(connection))
is_ok, err = connection:write('GET /request_sync HTTP/1.1\r\nConnection: keep-alive\r\n\r\n')