-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): add X-Kong-If-Reconfigured-Since header
- Loading branch information
1 parent
17044bc
commit ba7ff2c
Showing
4 changed files
with
129 additions
and
66 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ end | |
|
||
local _GLOBAL = { | ||
phases = phase_checker.phases, | ||
LAST_RECONFIGURATION = ngx.now(), | ||
} | ||
|
||
|
||
|
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
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 |
---|---|---|
|
@@ -522,7 +522,7 @@ local function update_in_place(new_version) | |
|
||
set_state(new) | ||
|
||
return true | ||
return "updated" | ||
end | ||
|
||
|
||
|
73 changes: 73 additions & 0 deletions
73
spec/02-integration/01-helpers/04-reconfiguration-conditional-get.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,73 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
|
||
describe("configuration conditional get", function() | ||
lazy_setup(function() | ||
helpers.get_db_utils(nil, {}) -- runs migrations | ||
assert(helpers.start_kong(env)) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.stop_kong() | ||
end) | ||
|
||
local proxy_client | ||
local admin_client | ||
|
||
before_each(function() | ||
proxy_client = helpers.proxy_client(5000) | ||
admin_client = helpers.admin_client(10000) | ||
end) | ||
|
||
after_each(function() | ||
if proxy_client then | ||
proxy_client:close() | ||
end | ||
if admin_client then | ||
admin_client:close() | ||
end | ||
end) | ||
|
||
it("waits until a change through the admin API has propagated to the proxy path", function() | ||
local res = admin_client:post( | ||
"/services", | ||
{ | ||
body = { | ||
protocol = "http", | ||
name = "foo", | ||
host = "127.0.0.1", | ||
}, | ||
headers = { ["Content-Type"] = "application/json" }, | ||
}) | ||
assert.res_status(201, res) | ||
res = admin_client:post( | ||
"/services/foo/routes", | ||
{ | ||
body = { | ||
paths = {"/blub"} | ||
}, | ||
headers = { ["Content-Type"] = "application/json" }, | ||
}) | ||
assert.res_status(201, res) | ||
local date = res.headers['Date'] | ||
-- flaky test below - we can't be sure that the configuration did not happen quicker than expected | ||
res = proxy_client:get( | ||
"/", | ||
{ headers = { ["X-Kong-If-Reconfigured-Since"] = date } } | ||
) | ||
assert.res_status(503, res) | ||
assert | ||
.with_timeout(30) | ||
.eventually( | ||
function() | ||
local client = helpers.proxy_client() | ||
local res = client:get( | ||
"/nonexistent", | ||
{ headers = { ["X-Kong-If-Reconfigured-Since"] = date } } | ||
) | ||
client:close() | ||
return res.status == 404 | ||
end) | ||
.is_truthy() | ||
end) | ||
end) |