-
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
test(*): implement new HTTP mocking #10885
Conversation
c9e149c
to
fe7868e
Compare
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.
Could you please move the tests from spec/helpers/http_mock_spec.lua
to spec/02-integration/01-helpers
?
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.
Please use the new mocking server replace some old code that used the old mocking servers.
97e1b0b
to
fbd28cb
Compare
fbd28cb
to
cbfaaa0
Compare
315ec03
to
b6a439e
Compare
b6a439e
to
5d77f9f
Compare
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.
spec/02-integration/05-proxy/03-upstream_headers_spec.lua
is red
5d77f9f
to
1b4db6f
Compare
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.
LGTM
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 like this proposal but I have a couple of comments and suggestions. Generally, do we have an understanding of the time that it takes to start up nginx compared to the thread and coroutine based mock servers?
local function register_assert(name, impl) | ||
eventually_MT["has_" .. name] = function(self, ...) | ||
return eventually_has(impl, self.__mock, ...) | ||
end | ||
|
||
eventually_MT["all_" .. name] = function(self, ...) | ||
return eventually_all(impl, self.__mock, ...) | ||
end | ||
|
||
local function reverse_impl(session, ...) | ||
local ok, err = pcall(impl, session, ...) | ||
if ok then | ||
error("we don't expect that: " .. (name or err), 2) | ||
end | ||
return true | ||
end | ||
|
||
eventually_MT["has_no_" .. name] = function(self, ...) | ||
return eventually_all(reverse_impl, self.__mock, ...) | ||
end | ||
|
||
eventually_MT["not_all_" .. name] = function(self, ...) | ||
return eventually_has(reverse_impl, self.__mock, ...) | ||
end | ||
end | ||
|
||
for name, impl in pairs(build_in_checks) do | ||
register_assert(name, impl) | ||
end |
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 looks cool and would probably be something to add to helpers.lua
or live in a separate module.
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.
We have this:
Line 453 in 458fd9f
local function eventually(state, arguments) |
Actually, the design is inspired by assert.eventually
.
This logic is coupled with self.__mock
and get_all_records()
. Maybe we will find a way to decouple them.
Starting a vanilla Nginx is really quick. I tried the test |
80edf0e
to
f1b91ef
Compare
f1b91ef
to
89282cf
Compare
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.
just some minor nits, please
Fix KAG-1148 apply suggestions Co-authored-by: Chrono <chrono_cpp@me.com> Co-authored-by: Hans Hübner <hans.huebner@gmail.com>
0ad116e
to
fc15f47
Compare
Summary
We have 3 types of implementation for HTTP mocking, each of which has some issues.
This PR introduces a new implementation to unify them with a dedicated Nginx instance.
It allows users to use the same logic as
start_kong
fixture. And it collects requests/responses/errors for later assertions on them.The collected information is then fetched from a debugging port, and a set of assertion APIs handles the fetching process.
It's also possible to extend this solution to support clients-to-server debugging API, e.g, to send a piece of text as the response body for the next request.
Checklist
Full changelog
start_kong
fixture,http_server
,mock_http
, andhttps_server
;Issue reference
Fix KAG-1148
Todo after this merged
Migrate current uses of
start_kong
fixture,http_server
,mock_http
, andhttps_server
.