Skip to content

Commit

Permalink
tests(clustering/rpc): add rpc service in custom plugin for testing (#…
Browse files Browse the repository at this point in the history
…13958)

(cherry picked from commit 88ffdda)
  • Loading branch information
chronolaw authored and ms2008 committed Dec 6, 2024
1 parent 872215f commit 3708ecd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
22 changes: 13 additions & 9 deletions spec/02-integration/18-hybrid_rpc/01-rpc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ local helpers = require "spec.helpers"
local cjson = require("cjson.safe")
local CLUSTERING_SYNC_STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS

-- we need incremental sync to verify rpc
for _, inc_sync in ipairs { "on" } do
-- register a test rpc service in custom plugin rpc-hello-test
for _, strategy in helpers.each_strategy() do
describe("Hybrid Mode RPC #" .. strategy .. " inc_sync=" .. inc_sync, function()
describe("Hybrid Mode RPC #" .. strategy, function()

lazy_setup(function()
helpers.get_db_utils(strategy, {
Expand All @@ -27,7 +26,8 @@ for _, strategy in helpers.each_strategy() do
cluster_listen = "127.0.0.1:9005",
nginx_conf = "spec/fixtures/custom_nginx.template",
cluster_rpc = "on",
cluster_incremental_sync = inc_sync, -- incremental sync
plugins = "bundled,rpc-hello-test",
cluster_incremental_sync = "off",
}))

assert(helpers.start_kong({
Expand All @@ -40,7 +40,8 @@ for _, strategy in helpers.each_strategy() do
proxy_listen = "0.0.0.0:9002",
nginx_conf = "spec/fixtures/custom_nginx.template",
cluster_rpc = "on",
cluster_incremental_sync = inc_sync, -- incremental sync
plugins = "bundled,rpc-hello-test",
cluster_incremental_sync = "off",
}))
end)

Expand Down Expand Up @@ -76,14 +77,17 @@ for _, strategy in helpers.each_strategy() do
assert(tonumber(m[2]) >= 9)

-- check the available rpc service
table.sort(v.rpc_capabilities)
assert.same("kong.sync.v2", v.rpc_capabilities[1])
return true
for _, c in ipairs(v.rpc_capabilities) do
if c == "kong.test" then
return true
end
end

return false
end
end
end, 10)
end)
end)
end)
end -- for _, strategy
end -- for inc_sync
15 changes: 8 additions & 7 deletions spec/02-integration/18-hybrid_rpc/04-concentrator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ local function obtain_dp_node_id() -- luacheck: ignore
end


-- we need incremental sync to verify rpc
for _, inc_sync in ipairs { "on" } do
-- register a test rpc service in custom plugin rpc-hello-test
for _, strategy in helpers.each_strategy() do
describe("Hybrid Mode RPC over DB concentrator #" .. strategy .. " inc_sync=" .. inc_sync, function()
describe("Hybrid Mode RPC over DB concentrator #" .. strategy, function()

lazy_setup(function()
helpers.get_db_utils(strategy, {
Expand All @@ -54,7 +53,8 @@ for _, strategy in helpers.each_strategy() do
admin_listen = "127.0.0.1:" .. helpers.get_available_port(),
nginx_conf = "spec/fixtures/custom_nginx.template",
cluster_rpc = "on",
cluster_incremental_sync = inc_sync, -- incremental sync
plugins = "bundled,rpc-hello-test",
cluster_incremental_sync = "off",
}))

assert(helpers.start_kong({
Expand All @@ -67,7 +67,8 @@ for _, strategy in helpers.each_strategy() do
nginx_conf = "spec/fixtures/custom_nginx.template",
cluster_telemetry_listen = "127.0.0.1:" .. helpers.get_available_port(),
cluster_rpc = "on",
cluster_incremental_sync = inc_sync, -- incremental sync
plugins = "bundled,rpc-hello-test",
cluster_incremental_sync = "off",
}))

assert(helpers.start_kong({
Expand All @@ -80,7 +81,8 @@ for _, strategy in helpers.each_strategy() do
proxy_listen = "0.0.0.0:9002",
nginx_conf = "spec/fixtures/custom_nginx.template",
cluster_rpc = "on",
cluster_incremental_sync = inc_sync, -- incremental sync
plugins = "bundled,rpc-hello-test",
cluster_incremental_sync = "off",
}))
end)

Expand All @@ -95,4 +97,3 @@ for _, strategy in helpers.each_strategy() do
--end)
end)
end -- for _, strategy
end -- for inc_sync
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- This software is copyright Kong Inc. and its licensors.
-- Use of the software is subject to the agreement between your organization
-- and Kong Inc. If there is no such agreement, use is governed by and
-- subject to the terms of the Kong Master Software License Agreement found
-- at https://konghq.com/enterprisesoftwarelicense/.
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

local RpcHelloTestHandler = {
VERSION = "1.0",
PRIORITY = 1000,
}


function RpcHelloTestHandler:init_worker()
kong.rpc.callbacks:register("kong.test.hello", function(node_id, greeting)
return "hello ".. greeting
end)
end


return RpcHelloTestHandler
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- This software is copyright Kong Inc. and its licensors.
-- Use of the software is subject to the agreement between your organization
-- and Kong Inc. If there is no such agreement, use is governed by and
-- subject to the terms of the Kong Master Software License Agreement found
-- at https://konghq.com/enterprisesoftwarelicense/.
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ]

return {
name = "rpc-hello-test",
fields = {
{
config = {
type = "record",
fields = {
},
},
},
},
}

0 comments on commit 3708ecd

Please sign in to comment.