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
  • Loading branch information
chronolaw authored Dec 6, 2024
1 parent 10ed044 commit 88ffdda
Show file tree
Hide file tree
Showing 4 changed files with 47 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 @@ -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
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 = {
},
},
},
},
}

1 comment on commit 88ffdda

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:88ffdda5904d0b375e973014951b65a107f593c5
Artifacts available https://github.com/Kong/kong/actions/runs/12194898133

Please sign in to comment.