Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a94f751

Browse files
committedNov 30, 2023
tests(*): use the same config to reload kong
Partial fix of KAG-3161
1 parent 3b09d87 commit a94f751

File tree

1 file changed

+56
-19
lines changed

1 file changed

+56
-19
lines changed
 

‎spec/helpers.lua

+56-19
Original file line numberDiff line numberDiff line change
@@ -3488,6 +3488,29 @@ local function get_grpc_target_port()
34883488
return 15010
34893489
end
34903490

3491+
local function kong_conf_args(env)
3492+
local prefix = env.prefix or conf.prefix
3493+
local nginx_conf = ""
3494+
3495+
3496+
local nginx_conf_flags = { "test" }
3497+
if env.nginx_conf then
3498+
nginx_conf = " --nginx-conf " .. env.nginx_conf
3499+
end
3500+
3501+
if TEST_COVERAGE_MODE == "true" then
3502+
-- render `coverage` blocks in the templates
3503+
nginx_conf_flags[#nginx_conf_flags + 1] = 'coverage'
3504+
end
3505+
3506+
local nginx_conf_flags_str = ""
3507+
if next(nginx_conf_flags) then
3508+
nginx_conf_flags_str = " --nginx-conf-flags " .. table.concat(nginx_conf_flags, ",")
3509+
end
3510+
3511+
return prefix, "--conf " .. TEST_CONF_PATH, nginx_conf, nginx_conf_flags_str
3512+
end
3513+
34913514

34923515
--- Start the Kong instance to test against.
34933516
-- The fixtures passed to this function can be 3 types:
@@ -3556,7 +3579,8 @@ local function start_kong(env, tables, preserve_prefix, fixtures)
35563579
error("arg #2 must be a list of tables to truncate")
35573580
end
35583581
env = env or {}
3559-
local prefix = env.prefix or conf.prefix
3582+
3583+
local prefix, conf_args, nginx_conf, flags = kong_conf_args(env)
35603584

35613585
-- go plugins are enabled
35623586
-- compile fixture go plugins if any setting mentions it
@@ -3577,23 +3601,6 @@ local function start_kong(env, tables, preserve_prefix, fixtures)
35773601

35783602
truncate_tables(db, tables)
35793603

3580-
local nginx_conf = ""
3581-
local nginx_conf_flags = { "test" }
3582-
if env.nginx_conf then
3583-
nginx_conf = " --nginx-conf " .. env.nginx_conf
3584-
end
3585-
3586-
if TEST_COVERAGE_MODE == "true" then
3587-
-- render `coverage` blocks in the templates
3588-
nginx_conf_flags[#nginx_conf_flags + 1] = 'coverage'
3589-
end
3590-
3591-
if next(nginx_conf_flags) then
3592-
nginx_conf_flags = " --nginx-conf-flags " .. table.concat(nginx_conf_flags, ",")
3593-
else
3594-
nginx_conf_flags = ""
3595-
end
3596-
35973604
if dcbp and not env.declarative_config and not env.declarative_config_string then
35983605
if not config_yml then
35993606
config_yml = prefix .. "/config.yml"
@@ -3609,7 +3616,7 @@ local function start_kong(env, tables, preserve_prefix, fixtures)
36093616
end
36103617

36113618
assert(render_fixtures(TEST_CONF_PATH .. nginx_conf, env, prefix, fixtures))
3612-
return kong_exec("start --conf " .. TEST_CONF_PATH .. nginx_conf .. nginx_conf_flags, env)
3619+
return kong_exec("start " .. conf_args .. nginx_conf .. flags, env)
36133620
end
36143621

36153622

@@ -3774,6 +3781,35 @@ local function reload_kong(strategy, ...)
37743781
end
37753782

37763783

3784+
local DEFAULT_WAIT_OPT = {
3785+
timeout = 10,
3786+
step = 2,
3787+
}
3788+
3789+
3790+
--- Reload the Kong instance.
3791+
local function reload_kong_ex(env, wait_opts)
3792+
env = env or {}
3793+
local _, conf_args, nginx_conf, flags = kong_conf_args(env)
3794+
3795+
wait_opts = wait_opts or DEFAULT_WAIT_OPT
3796+
local no_wait = wait_opts.no_wait
3797+
3798+
local workers, ret, err
3799+
if not no_wait then
3800+
workers = get_kong_workers()
3801+
end
3802+
3803+
ret, err = kong_exec("reload " .. conf_args .. nginx_conf .. flags, env)
3804+
3805+
if (not no_wait) and ret then
3806+
wait_until_no_common_workers(workers, wait_opts.expected_total, wait_opts)
3807+
end
3808+
3809+
return ret, err
3810+
end
3811+
3812+
37773813
--- Simulate a Hybrid mode DP and connect to the CP specified in `opts`.
37783814
-- @function clustering_client
37793815
-- @param opts Options to use, the `host`, `port`, `cert` and `cert_key` fields
@@ -4049,6 +4085,7 @@ end
40494085
cleanup_kong = cleanup_kong,
40504086
restart_kong = restart_kong,
40514087
reload_kong = reload_kong,
4088+
reload_kong_ex = reload_kong_ex,
40524089
get_kong_workers = get_kong_workers,
40534090
wait_until_no_common_workers = wait_until_no_common_workers,
40544091

0 commit comments

Comments
 (0)
Please sign in to comment.