diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-09-10 15:19:16 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-09-10 15:19:16 +0100 |
commit | a77f6d5515077c0b6912ce957d7c53bf0c526a58 (patch) | |
tree | 1380029b0bf7418249a8df99e03c03f6ee18fcb0 /test/functional/lua | |
parent | 1b5cef0e884b49430d5cac902a366703beef5439 (diff) | |
download | rspamd-a77f6d5515077c0b6912ce957d7c53bf0c526a58.tar.gz rspamd-a77f6d5515077c0b6912ce957d7c53bf0c526a58.zip |
[Test] Added test for Redis API
Diffstat (limited to 'test/functional/lua')
-rw-r--r-- | test/functional/lua/redis.lua | 88 | ||||
-rw-r--r-- | test/functional/lua/rspamadm/test_redis_client.lua | 40 | ||||
-rw-r--r-- | test/functional/lua/tcp.lua | 7 |
3 files changed, 134 insertions, 1 deletions
diff --git a/test/functional/lua/redis.lua b/test/functional/lua/redis.lua new file mode 100644 index 000000000..841b20787 --- /dev/null +++ b/test/functional/lua/redis.lua @@ -0,0 +1,88 @@ +--[[[ +-- Just a test for Redis API +--]] + +local logger = require "rspamd_logger" +local redis_lua = require "lua_redis" +local lua_util = require "lua_util" + +local redis_params +local N = 'redis_test' + +local lua_script = [[ +local f = function() end +return "hello from lua on redis" +]] + +local function redis_simple_async_symbol(task) + local function redis_cb(err, data) + if err then + task:insert_result('REDIS_ASYNC_ERROR', 1.0, err) + else + task:insert_result('REDIS_ASYNC', 1.0, data) + end + end + + redis_lua.rspamd_redis_make_request( + task, + redis_params, + "test_key", + false, + redis_cb, + 'GET', + {'test_key'} + ) +end + +local function redis_symbol(task) + + local params = lua_util.deepcopy(redis_params) + params.task = task + local is_ok, connection = redis_lua.redis_connect_sync(params) + + logger.infox(task, "connect: %1, %2", is_ok, connection) + + if not is_ok then + task:insert_result('REDIS_ERROR', 1.0, connection) + return + end + + local err, data + + is_ok, err = connection:add_cmd('EVAL', {lua_script, 0}) + logger.infox(task, "add_cmd: %1, %2", is_ok, err) + + if not is_ok then + task:insert_result('REDIS_ERROR_2', 1.0, err) + return + end + + is_ok,data = connection:exec() + + logger.infox(task, "exec: %1, %2", is_ok, data) + + if not is_ok then + task:insert_result('REDIS_ERROR_3', 1.0, data) + return + end + + task:insert_result('REDIS', 1.0, data) + +end + +redis_params = rspamd_parse_redis_server(N) + +rspamd_config:register_symbol({ + name = 'SIMPLE_REDIS_ASYNC_TEST', + score = 1.0, + callback = redis_simple_async_symbol, + no_squeeze = true +}) + +rspamd_config:register_symbol({ + name = 'REDIS_TEST', + score = 1.0, + callback = redis_symbol, + no_squeeze = true +}) +-- ]] diff --git a/test/functional/lua/rspamadm/test_redis_client.lua b/test/functional/lua/rspamadm/test_redis_client.lua new file mode 100644 index 000000000..7de82cd96 --- /dev/null +++ b/test/functional/lua/rspamadm/test_redis_client.lua @@ -0,0 +1,40 @@ +local logger = require "rspamd_logger" +local redis = require "lua_redis" +local upstream_list = require "rspamd_upstream_list" + +local upstreams_write = upstream_list.create('127.0.0.1', 56379) +local upstreams_read = upstream_list.create('127.0.0.1', 56379) + +local is_ok, connection = redis.redis_connect_sync({ + write_servers = upstreams_write, + read_servers = upstreams_read, + config = rspamd_config, + ev_base = rspamadm_ev_base, + session = rspamadm_session, + timeout = 2 +}) + + +local lua_script = [[ +local f = function() end +--for k = 1,100000000 do +-- for i=1,100000000 do +-- f() +-- end +--end +return "hello from lua on redis" +]] + +local a,b = connection:add_cmd('EVAL', {lua_script, 0}) +local is_ok,ver = connection:exec() + +print(is_ok, ver) + +--[[ +a,b = connection:add_cmd('EVAL', {lua_script, 0}) +print(a,b) + +is_ok,ver = connection:exec() + +print(is_ok, ver) +]]
\ No newline at end of file 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') |