diff --git a/lib/resty/etcd/health_check.lua b/lib/resty/etcd/health_check.lua index 88aa301..55911e6 100644 --- a/lib/resty/etcd/health_check.lua +++ b/lib/resty/etcd/health_check.lua @@ -163,6 +163,9 @@ function _M.init(opts) _M.conf = conf return _M, nil end + + -- Keep the existing configuration when the health-check mode is unchanged. + return _M, nil end return _M diff --git a/t/v3/health_check.t b/t/v3/health_check.t index 7c3f3b4..463df7a 100644 --- a/t/v3/health_check.t +++ b/t/v3/health_check.t @@ -957,3 +957,30 @@ GET /t choose_endpoint(): choose endpoint: http://127.0.0.1:12379 choose_endpoint(): choose endpoint: http://127.0.0.1:22379 choose_endpoint(): choose endpoint: http://127.0.0.1:32379 + + +=== TEST 23: repeated health-check initialization returns the module +--- http_config eval: $::HttpConfig +--- config + location /t { + content_by_lua_block { + local health_check = require("resty.etcd.health_check") + local first, first_err = health_check.init({ + shm_name = "etcd_cluster_health_check", + }) + assert(first == health_check and first_err == nil) + + local second, second_err = health_check.init({ + shm_name = "etcd_cluster_health_check", + }) + assert(second == health_check and second_err == nil) + + ngx.say("done") + } + } +--- request +GET /t +--- response_body +done +--- no_error_log +[error]