-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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): rpc mock/hook #14030
base: master
Are you sure you want to change the base?
Conversation
c79e2be
to
5438bcc
Compare
spec/helpers/rpc_mock/server.lua
Outdated
config = {}, | ||
}) | ||
|
||
assert(helpers.start_kong(self)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start a mock cp to proxy client's rpc request to DP
spec/helpers/rpc_mock/server.lua
Outdated
|
||
assert(helpers.start_kong(self)) | ||
|
||
self.proxy_client = client.new({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client -> mock cp --> tested DP
spec/helpers/rpc_mock/server.lua
Outdated
self:enable_inception() | ||
end | ||
|
||
self.proxy_client.callbacks:register("kong.rpc.proxy.mock", function(proxy_id, proxy_payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mock cp will rpc call this callback to forward [the RPC call request from tested DP]
to [client]
server_mock = server.new() | ||
assert(server_mock:start()) | ||
|
||
assert(helpers.start_kong({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: add a comment to explain this is.a tested DP
10b37a0
to
8656633
Compare
8656633
to
8a26357
Compare
8a26357
to
5b3a82a
Compare
local prehook = self.prehooks[method] or self.prehooks["*"] | ||
local posthook = self.posthooks[method] or self.posthooks["*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need add some comment for prehook and post hook
local helpers = require("spec.helpers") | ||
local client = require("spec.helpers.rpc_mock.client") | ||
local default_cert = require("spec.helpers.rpc_mock.default").default_cert | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly recommend you to write a callback and diagram in the comment like, or you could write a design doc
-- Diagram:
--
-- mock client -> mock server -> tested DP
--
-- Callback chains:
--
-- func1
-- -> func2
-- -> func3 ...
otherwise other developers or reviewers find it hard to understand, today i talked with @chronolaw , he found it hard to understand what the server.lua does here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a good way is that you could write a test case to run this mock client -> mock server -> tested DP
progress, i find there is no case for mock server<>tested DP
. Then we could explain the progress with that case, that might be easy to understand for reviewers.
9d4b947
to
337dce1
Compare
337dce1
to
d006c6f
Compare
Summary
RPC needs mock tests
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix KAG-5551