-
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): add cases for sync.v2.get_delta #14151
Open
chronolaw
wants to merge
4
commits into
master
Choose a base branch
from
tests/mock_v2_get_delta
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
spec/02-integration/18-hybrid_rpc/08-sync_v2_get_delta_spec.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
|
||
-- register a rpc connected event in custom plugin rpc-get-delta-test | ||
-- ENABLE rpc sync on cp side for testing sync.v2.get_delta | ||
-- DISABLE rpc sync on dp side | ||
for _, strategy in helpers.each_strategy() do | ||
describe("Hybrid Mode RPC #" .. strategy, function() | ||
|
||
lazy_setup(function() | ||
helpers.get_db_utils(strategy, { | ||
"clustering_data_planes", | ||
}) -- runs migrations | ||
|
||
assert(helpers.start_kong({ | ||
role = "control_plane", | ||
cluster_cert = "spec/fixtures/kong_clustering.crt", | ||
cluster_cert_key = "spec/fixtures/kong_clustering.key", | ||
database = strategy, | ||
cluster_listen = "127.0.0.1:9005", | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
plugins = "bundled", | ||
nginx_worker_processes = 4, -- multiple workers | ||
cluster_rpc = "on", -- enable rpc | ||
cluster_rpc_sync = "on", -- enable rpc sync | ||
})) | ||
|
||
assert(helpers.start_kong({ | ||
role = "data_plane", | ||
database = "off", | ||
prefix = "servroot2", | ||
cluster_cert = "spec/fixtures/kong_clustering.crt", | ||
cluster_cert_key = "spec/fixtures/kong_clustering.key", | ||
cluster_control_plane = "127.0.0.1:9005", | ||
proxy_listen = "0.0.0.0:9002", | ||
nginx_conf = "spec/fixtures/custom_nginx.template", | ||
plugins = "bundled,rpc-get-delta-test", | ||
nginx_worker_processes = 4, -- multiple workers | ||
cluster_rpc = "on", -- enable rpc | ||
cluster_rpc_sync = "off", -- disable rpc sync | ||
})) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.stop_kong("servroot2") | ||
helpers.stop_kong() | ||
end) | ||
|
||
describe("sync.v2.get_delta works", function() | ||
it("in cp side", function() | ||
local name = "servroot2/logs/error.log" | ||
|
||
-- dp logs | ||
helpers.pwait_until(function() | ||
assert.logfile(name).has.line( | ||
"kong.sync.v2.get_delta ok", true) | ||
assert.logfile(name).has.no.line( | ||
"assertion failed", true) | ||
assert.logfile(name).has.no.line( | ||
"[error]", true) | ||
return true | ||
end, 10) | ||
|
||
local name = nil | ||
|
||
-- cp logs | ||
helpers.pwait_until(function() | ||
assert.logfile(name).has.no.line( | ||
"assertion failed", true) | ||
assert.logfile(name).has.no.line( | ||
"[error]", true) | ||
return true | ||
end, 10) | ||
|
||
end) | ||
end) | ||
end) | ||
end -- for _, strategy |
60 changes: 60 additions & 0 deletions
60
spec/fixtures/custom_plugins/kong/plugins/rpc-get-delta-test/handler.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
local rep = string.rep | ||
local isempty = require("table.isempty") | ||
|
||
|
||
local RpcSyncV2GetDeltaTestHandler = { | ||
VERSION = "1.0", | ||
PRIORITY = 1000, | ||
} | ||
|
||
|
||
function RpcSyncV2GetDeltaTestHandler:init_worker() | ||
local worker_events = assert(kong.worker_events) | ||
|
||
-- if rpc is ready we will send test calls | ||
-- cp's version now is "v02_00000" | ||
worker_events.register(function(capabilities_list) | ||
local node_id = "control_plane" | ||
local method = "kong.sync.v2.get_delta" | ||
|
||
-- no field `default` for kong.sync.v2.get_delta | ||
local msg = {} | ||
local res, err = kong.rpc:call(node_id, method, msg) | ||
|
||
assert(not res) | ||
assert(err == "default namespace does not exist inside params") | ||
|
||
-- version is invalid | ||
local msg = { default = { version = rep("A", 32), }, } | ||
local res, err = kong.rpc:call(node_id, method, msg) | ||
|
||
assert(type(res) == "table") | ||
assert(not isempty(res.default.deltas)) | ||
assert(res.default.wipe == true) | ||
assert(not err) | ||
|
||
-- dp's version is greater than cp's version | ||
local msg = { default = { version = "v02_" .. rep("A", 28), }, } | ||
local res, err = kong.rpc:call(node_id, method, msg) | ||
|
||
assert(type(res) == "table") | ||
assert(not isempty(res.default.deltas)) | ||
assert(res.default.wipe == true) | ||
assert(not err) | ||
|
||
-- dp's version is equal to cp's version | ||
local msg = { default = { version = "v02_" .. rep("0", 28), }, } | ||
local res, err = kong.rpc:call(node_id, method, msg) | ||
|
||
assert(type(res) == "table") | ||
assert(isempty(res.default.deltas)) | ||
assert(res.default.wipe == false) | ||
assert(not err) | ||
|
||
ngx.log(ngx.DEBUG, "kong.sync.v2.get_delta ok") | ||
|
||
end, "clustering:jsonrpc", "connected") | ||
end | ||
|
||
|
||
return RpcSyncV2GetDeltaTestHandler |
12 changes: 12 additions & 0 deletions
12
spec/fixtures/custom_plugins/kong/plugins/rpc-get-delta-test/schema.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
return { | ||
name = "rpc-get-delta-test", | ||
fields = { | ||
{ | ||
config = { | ||
type = "record", | ||
fields = { | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This kind of assertion already has timeout as the input parameter, so the
pwait_until
is not required.kong/spec/03-plugins/04-file-log/01-log_spec.lua
Line 562 in e9510e9
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.
Not sure about it, if assertion fails
wait_until
may crush, sopwait_until
is a better choice.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 checked the code in spec/internal/wait.lua, pwait_until is different from wait_until, it can deal with assertion failings.
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.
Maybe I'm not clear enough,
assert.logfile().has.line(pattern, boolean, timeout)
, we can pass the timeout into this assertion, so we don't need to warp it withwait_until
orpwait_until
.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.
Got, let me try it.
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.
It works, but the tests take more time than pwait_until, so my opinion is keeping it.