Skip to content

Commit

Permalink
fix 08-lazy_export_spec.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Sep 25, 2024
1 parent dfe02b0 commit 4e6d5a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions kong/clustering/services/sync/rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function _M:init_cp(manager)
-- Params: versions: list of current versions of the database
-- { { namespace = "default", current_version = 1000, }, }
manager.callbacks:register("kong.sync.v2.get_delta", function(node_id, current_versions)
ngx_log(ngx_DEBUG, "[kong.sync.v2] config push (connected client)")

local rpc_peers
if kong.rpc then
rpc_peers = kong.rpc:get_peers()
Expand Down
35 changes: 25 additions & 10 deletions spec/02-integration/09-hybrid_mode/08-lazy_export_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local helpers = require "spec.helpers"

local admin_client

local function cp(strategy)
local function cp(strategy, inc_sync)
helpers.get_db_utils(strategy) -- make sure the DB is fresh n' clean
assert(helpers.start_kong({
role = "control_plane",
Expand All @@ -14,6 +14,7 @@ local function cp(strategy)
-- additional attributes for PKI:
cluster_mtls = "pki",
cluster_ca_cert = "spec/fixtures/ocsp_certs/ca.crt",
cluster_incremental_sync = inc_sync,
}))
admin_client = assert(helpers.admin_client())
end
Expand All @@ -34,7 +35,7 @@ local function touch_config()
}))
end

local function json_dp()
local function json_dp(inc_sync)
assert(helpers.start_kong({
role = "data_plane",
database = "off",
Expand All @@ -47,30 +48,37 @@ local function json_dp()
cluster_mtls = "pki",
cluster_server_name = "kong_clustering",
cluster_ca_cert = "spec/fixtures/ocsp_certs/ca.crt",
cluster_incremental_sync = inc_sync,
}))
end


for _, inc_sync in ipairs { "on", "off" } do
for _, strategy in helpers.each_strategy() do

describe("lazy_export with #".. strategy, function()
describe("lazy_export with #".. strategy .. " inc_sync=" .. inc_sync, function()
describe("no DP", function ()
setup(function()
cp(strategy)
cp(strategy, inc_sync)
end)
teardown(function ()
helpers.stop_kong()
end)
it("test", function ()
touch_config()
assert.logfile().has.line("[clustering] skipping config push (no connected clients)", true)
if inc_sync == "on" then
assert.logfile().has.no.line("[kong.sync.v2] config push (connected client)", true)

else
assert.logfile().has.line("[clustering] skipping config push (no connected clients)", true)
end
end)
end)

describe("only json DP", function()
setup(function()
cp(strategy)
json_dp()
cp(strategy, inc_sync)
json_dp(inc_sync)
end)
teardown(function ()
helpers.stop_kong("dp1")
Expand All @@ -79,11 +87,18 @@ describe("lazy_export with #".. strategy, function()

it("test", function ()
touch_config()
assert.logfile().has.line("[clustering] exporting config", true)
assert.logfile().has.line("[clustering] config pushed to 1 data-plane nodes", true)
if inc_sync == "on" then
assert.logfile().has.line("[kong.sync.v2] config push (connected client)", true)
assert.logfile().has.line("[kong.sync.v2] database is empty or too far behind for node_id", true)

else
assert.logfile().has.line("[clustering] exporting config", true)
assert.logfile().has.line("[clustering] config pushed to 1 data-plane nodes", true)
end
end)
end)

end)

end
end -- for _, strategy
end -- for inc_sync

0 comments on commit 4e6d5a4

Please sign in to comment.