This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 298114f test: make test etcd healthcheck stable (#5239)
298114f is described below
commit 298114f8d1471fa6070499f6d80ca0799c1adaa2
Author: tzssangglass <[email protected]>
AuthorDate: Fri Oct 15 09:45:55 2021 +0800
test: make test etcd healthcheck stable (#5239)
---
apisix/core/etcd.lua | 10 +++++++++-
t/cli/test_etcd_healthcheck.sh | 5 -----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua
index 40a44ec..793ece5 100644
--- a/apisix/core/etcd.lua
+++ b/apisix/core/etcd.lua
@@ -17,10 +17,10 @@
local fetch_local_conf = require("apisix.core.config_local").local_conf
local etcd = require("resty.etcd")
local clone_tab = require("table.clone")
+local health_check = require("resty.etcd.health_check")
local ipairs = ipairs
local string = string
local tonumber = tonumber
-
local _M = {}
@@ -56,6 +56,14 @@ local function new()
end
end
+ -- enable etcd health check retry for curr worker
+ if not health_check.conf then
+ health_check.init({
+ max_fails = #etcd_conf.http_host,
+ retry = true,
+ })
+ end
+
local etcd_cli
etcd_cli, err = etcd.new(etcd_conf)
if not etcd_cli then
diff --git a/t/cli/test_etcd_healthcheck.sh b/t/cli/test_etcd_healthcheck.sh
index bc7e3dc..34ca4d2 100755
--- a/t/cli/test_etcd_healthcheck.sh
+++ b/t/cli/test_etcd_healthcheck.sh
@@ -45,8 +45,6 @@ docker-compose -f ./t/cli/docker-compose-etcd-cluster.yaml up
-d
make init && make run
docker stop ${ETCD_NAME_0}
-# wait to etcd health check marks ETCD_NAME_0 as unhealthy
-sleep 3
code=$(curl -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
if [ ! $code -eq 200 ]; then
echo "failed: apisix got effect when one etcd node out of a cluster
disconnected"
@@ -55,9 +53,6 @@ fi
docker start ${ETCD_NAME_0}
docker stop ${ETCD_NAME_1}
-# after 2 rounds of timeout, etcd health check marks ETCD_NAME_1 as unhealthy,
-# and ETCD_NAME_1 is in fail_timeout state, it won't be selected to create a
new etcd connection
-sleep 5
code=$(curl -o /dev/null -s -w %{http_code}
http://127.0.0.1:9080/apisix/admin/routes -H 'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1')
if [ ! $code -eq 200 ]; then
echo "failed: apisix got effect when one etcd node out of a cluster
disconnected"