Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(clustering/rpc): add rpc service in custom plugin for testing #13958

Merged
merged 8 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2,10 +2,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 @@ -20,7 +19,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 @@ -33,7 +33,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 @@ -69,14 +70,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
chronolaw marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -28,10 +28,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 @@ -47,7 +46,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 @@ -59,7 +59,8 @@ for _, strategy in helpers.each_strategy() do
cluster_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 @@ -72,7 +73,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 @@ -87,4 +89,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,14 @@
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,12 @@
return {
name = "rpc-hello-test",
fields = {
{
config = {
type = "record",
fields = {
},
},
},
},
}
Loading