From 798cf9f9d18fd450b58f3b6fef79469dcba1e688 Mon Sep 17 00:00:00 2001 From: YuanSheng Wang Date: Tue, 28 Apr 2020 16:01:04 +0800 Subject: [PATCH] bugfix: init `clean_handlers` when add new item from etcd. (#1412) fix #1384 --- apisix/core/config_etcd.lua | 1 + t/node/healthcheck.t | 68 ++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/apisix/core/config_etcd.lua b/apisix/core/config_etcd.lua index 484e6ef9fc7e..dd0a5487bac1 100644 --- a/apisix/core/config_etcd.lua +++ b/apisix/core/config_etcd.lua @@ -285,6 +285,7 @@ local function sync_data(self) end elseif res.value then + res.clean_handlers = {} insert_tab(self.values, res) self.values_hash[key] = #self.values res.value.id = key diff --git a/t/node/healthcheck.t b/t/node/healthcheck.t index 22e8b082ed41..96ff4f48217c 100644 --- a/t/node/healthcheck.t +++ b/t/node/healthcheck.t @@ -14,15 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -BEGIN { - if ($ENV{TEST_NGINX_CHECK_LEAK}) { - $SkipReason = "unavailable for the hup tests"; - - } else { - $ENV{TEST_NGINX_USE_HUP} = 1; - undef $ENV{TEST_NGINX_USE_STAP}; - } -} use t::APISIX 'no_plan'; @@ -498,3 +489,62 @@ qr{.*http://127.0.0.1:1960/server_port.* .*http://127.0.0.1:1961/server_port.* .*http://127.0.0.1:1961/server_port.*} --- timeout: 10 + + + +=== TEST 11: add new routh with healthcheck attribute +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + for i = 1, 3 do + t('/apisix/admin/routes/' .. i, + ngx.HTTP_PUT, + [[{ + "uri": "/server_port", + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:1980": 1 + }, + "checks": { + "active": { + "http_path": "/status", + "host": "foo.com", + "healthy": { + "interval": 1, + "successes": 1 + }, + "unhealthy": { + "interval": 1, + "http_failures": 2 + } + } + } + } + }]] + ) + + ngx.sleep(0.1) + + local code, body = t('/server_port', ngx.HTTP_GET) + ngx.say("code: ", code, " body: ", body) + + code, body = t('/apisix/admin/routes/' .. i, ngx.HTTP_DELETE) + ngx.say("delete code: ", code) + + ngx.sleep(0.1) + end + } + } +--- request +GET /t +--- response_body +code: 200 body: passed +delete code: 200 +code: 200 body: passed +delete code: 200 +code: 200 body: passed +delete code: 200 +--- no_error_log +[error]