From 3bcecb626f565ff1238c24e217159393b523b885 Mon Sep 17 00:00:00 2001 From: Akayeshmantha Date: Sat, 25 Apr 2020 19:20:08 +0200 Subject: [PATCH] fix the test issues. --- apisix/plugins/syslog.lua | 11 ++++------- t/plugin/syslog.t | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apisix/plugins/syslog.lua b/apisix/plugins/syslog.lua index dd24ed1fbce24..1eb6ac8d9310f 100644 --- a/apisix/plugins/syslog.lua +++ b/apisix/plugins/syslog.lua @@ -16,7 +16,7 @@ -- local core = require("apisix.core") local log_util = require("apisix.utils.log-util") -local logger_socket = require "resty.logger.socket" +local logger_socket = require("resty.logger.socket") local plugin_name = "syslog" local ngx = ngx @@ -49,15 +49,12 @@ function _M.check_schema(conf) end function _M.flush_syslog(logger) - if logger.initted() then - local ok, err = logger:flush() + local ok, err = logger:flush(logger) if not ok then core.log.error("failed to flush message:", err) end - end end - function _M.log(conf) local entry = log_util.get_full_log(ngx) @@ -79,11 +76,11 @@ function _M.log(conf) tls = conf.tls, }) - if not ok then + if not logger then core.log.error("failed when initiating the sys logger processor", err) end - local ok, err = logger.log(core.json.encode(entry)) + local ok, err = logger:log(core.json.encode(entry)) if not ok then core.log.error("failed to log message", err) end diff --git a/t/plugin/syslog.t b/t/plugin/syslog.t index 606cb01bc91f3..05a5cd1dd80c0 100644 --- a/t/plugin/syslog.t +++ b/t/plugin/syslog.t @@ -110,7 +110,7 @@ done }, "upstream": { "nodes": { - "127.0.0.1:1984": 1 + "127.0.0.1:1980": 1 }, "type": "roundrobin" }, @@ -127,7 +127,7 @@ done }, "upstream": { "nodes": { - "127.0.0.1:1984": 1 + "127.0.0.1:1980": 1 }, "type": "roundrobin" }, @@ -171,13 +171,19 @@ hello world local plugin = require("apisix.plugins.syslog") local logger_socket = require "resty.logger.socket" local logger, err = logger_socket:new({ - host = "127.0.0.1", - port = 5044, - flush_limit = 1, + host = "127.0.0.1", + port = 5044, + flush_limit = 100, }) - if not logger then - ngx.log(ngx.ERR, "failed to create logger: ", err) + local bytes, err = logger:log("abc") + if err then + ngx.log(ngx.ERR, err) + end + + local bytes, err = logger:log("efg") + if err then + ngx.log(ngx.ERR, err) end local ok, err = plugin.flush_syslog(logger)