From fedc9fc438d3caac98b805b6926d3d245d7a505b Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 16 Jan 2025 12:47:49 +0800 Subject: [PATCH] basic tests --- .../09-notify_new_version_spec.lua | 28 ++++++++----------- .../rpc-notify-new-version-test/handler.lua | 7 ++++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/spec/02-integration/18-hybrid_rpc/09-notify_new_version_spec.lua b/spec/02-integration/18-hybrid_rpc/09-notify_new_version_spec.lua index dd4094c57bb..d798516172d 100644 --- a/spec/02-integration/18-hybrid_rpc/09-notify_new_version_spec.lua +++ b/spec/02-integration/18-hybrid_rpc/09-notify_new_version_spec.lua @@ -51,26 +51,22 @@ for _, strategy in helpers.each_strategy() do local name = "servroot2/logs/error.log" -- dp logs - helpers.pwait_until(function() - assert.logfile(name).has.line( - "kong.sync.v2.get_delta ok", true) - assert.logfile(name).has.no.line( - "assertion failed", true) - assert.logfile(name).has.no.line( - "[error]", true) - return true - end, 10) + assert.logfile(name).has.line( + "kong.sync.v2.notify_new_version ok", true, 10) + assert.logfile(name).has.no.line( + "assertion failed", true, 0) + assert.logfile(name).has.no.line( + "[error]", true, 0) local name = nil -- cp logs - helpers.pwait_until(function() - assert.logfile(name).has.no.line( - "assertion failed", true) - assert.logfile(name).has.no.line( - "[error]", true) - return true - end, 10) + assert.logfile(name).has.line( + "kong.sync.v2.get_delta ok", true, 10) + assert.logfile(name).has.no.line( + "assertion failed", true, 0) + assert.logfile(name).has.no.line( + "[error]", true, 0) end) end) diff --git a/spec/fixtures/custom_plugins/kong/plugins/rpc-notify-new-version-test/handler.lua b/spec/fixtures/custom_plugins/kong/plugins/rpc-notify-new-version-test/handler.lua index 27c3543d3f0..d73ce087fe6 100644 --- a/spec/fixtures/custom_plugins/kong/plugins/rpc-notify-new-version-test/handler.lua +++ b/spec/fixtures/custom_plugins/kong/plugins/rpc-notify-new-version-test/handler.lua @@ -11,7 +11,7 @@ local RpcSyncV2NotifyNewVersioinTestHandler = { function RpcSyncV2NotifyNewVersioinTestHandler:init_worker() -- mock function on cp side kong.rpc.callbacks:register("kong.sync.v2.get_delta", function(node_id, current_versions) - local latest_version = "v02_" .. string.rep("1", 28) + local latest_version = string.format("v02_%028d", 10) local fake_uuid1 = "00000000-0000-0000-0000-111111111111" local fake_uuid2 = "00000000-0000-0000-0000-222222222222" @@ -38,11 +38,14 @@ function RpcSyncV2NotifyNewVersioinTestHandler:init_worker() } } + ngx.log(ngx.DEBUG, "kong.sync.v2.get_delta ok") + return { default = { deltas = deltas, wipe = true, }, } end) -- call dp's sync.v2.notify_new_version kong.rpc.callbacks:register("kong.test.notify_new_version", function(node_id) + return true end) local worker_events = assert(kong.worker_events) @@ -52,6 +55,8 @@ function RpcSyncV2NotifyNewVersioinTestHandler:init_worker() local node_id = "control_plane" local res, err = kong.rpc:call(node_id, "kong.test.notify_new_version") + assert(res == true) + assert(not err) ngx.log(ngx.DEBUG, "kong.sync.v2.notify_new_version ok")