Skip to content

Commit

Permalink
rpc connected event
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Jan 10, 2025
1 parent 1c697bb commit 6632786
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 60 deletions.
52 changes: 4 additions & 48 deletions spec/02-integration/18-hybrid_rpc/06-batch-rpc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,66 +42,22 @@ for _, strategy in helpers.each_strategy() do

describe("batch works", function()
it("DP calls CP via batching", function()
local admin_client = helpers.admin_client(10000)
finally(function()
admin_client:close()
end)

local res = assert(admin_client:post("/services", {
body = { name = "mockbin-service", url = "https://127.0.0.1:15556/request", },
headers = {["Content-Type"] = "application/json"}
}))
assert.res_status(201, res)

res = assert(admin_client:post("/services/mockbin-service/routes", {
body = { paths = { "/" }, },
headers = {["Content-Type"] = "application/json"}
}))
local body = assert.res_status(201, res)
local json = cjson.decode(body)
local route_id = json.id

-- add a plugin for route
res = assert(admin_client:post("/routes/" .. route_id .. "/plugins", {
body = { name = "rpc-batch-test" },
headers = {["Content-Type"] = "application/json"}
}))
assert.res_status(201, res)

helpers.wait_until(function()
local proxy_client = helpers.http_client("127.0.0.1", 9002)

res = proxy_client:send({
method = "GET",
path = "/",
})

local status = res and res.status
proxy_client:close()
if status == 200 then
return true
end
end, 10)

helpers.pwait_until(function()
assert.logfile().has.line(
"[rpc] got batch RPC call: 1", true)
assert.logfile().has.line(
"kong.test.batch called: world", true)

-- this may cause flakiness
--assert.logfile("servroot2/logs/error.log").has.line(
-- "[rpc] sent batch RPC call: 1", true)
assert.logfile("servroot2/logs/error.log").has.line(
"[rpc] sent batch RPC call: 1", true)

assert.logfile("servroot2/logs/error.log").has.line(
"[rpc] got batch RPC call: 1", true)
assert.logfile("servroot2/logs/error.log").has.line(
"kong.test.batch called: hello world", true)


-- this may cause flakiness
--assert.logfile("servroot2/logs/error.log").has.line(
-- "[rpc] sent batch RPC call: 2", true)
assert.logfile("servroot2/logs/error.log").has.line(
"[rpc] sent batch RPC call: 2", true)

assert.logfile().has.line(
"[rpc] got batch RPC call: 2", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ function RpcBatchTestHandler:init_worker()
ngx.log(ngx.DEBUG, "kong.test.batch called: ", greeting)
return "hello ".. greeting
end)
end

local worker_events = assert(kong.worker_events)

function RpcBatchTestHandler:access()
kong.rpc:set_batch(1)
-- if rpc is ready we will start to sync
worker_events.register(function(capabilities_list)
kong.rpc:set_batch(1)

local res, err = kong.rpc:call("control_plane", "kong.test.batch", "world")
if not res then
return kong.response.exit(500, err)
end
local res, err = kong.rpc:call("control_plane", "kong.test.batch", "world")
if not res then
return
end

ngx.log(ngx.DEBUG, "kong.test.batch called: ", res)
ngx.log(ngx.DEBUG, "kong.test.batch called: ", res)

kong.rpc:set_batch(2)
kong.rpc:notify("control_plane", "kong.test.batch", "kong")
kong.rpc:notify("control_plane", "kong.test.batch", "gateway")
kong.rpc:set_batch(2)
kong.rpc:notify("control_plane", "kong.test.batch", "kong")
kong.rpc:notify("control_plane", "kong.test.batch", "gateway")

return kong.response.exit(200, res)
end, "clustering:jsonrpc", "connected")
end


Expand Down

0 comments on commit 6632786

Please sign in to comment.