-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: improve numerous http tests #12930
Conversation
95e23cd
to
2489dfe
Compare
* Use common.mustCall where appropriate * Remove extraneous console output * Misc cleanups
2489dfe
to
b23ec7c
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 with the same nit throughout.
c.write(request_generator()); | ||
}); | ||
c.on('connect', common.mustCall(() => c.write(request_generator()))); | ||
c.on('data', common.mustCall((chunk) => server_response += chunk)); |
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 don't think we should add common.mustCall()
around 'data'
event handlers because they can be called a number of times.
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.
The idea for me is that tests should be predictable, and that for each of these tests, the number of times an event like data
would be called should be deterministic. If a change is made that changes that, then the test should pick up on it and update the test. Doing so would increase the visibility of such changes.
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.
common.mustCall()
takes an expected:int
as second argument.
I'll write a PR to have it expect '+'
as "more than zero".
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 agree with that point. But aren't we at the mercy of different platforms and whatnot for the flow of data? If it can be done reliably, and without platform specific checks, then 👍
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.
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.
Given that there's no way for the test to pass if the callback is not called (because server_response
will not have the expected data), I would be inclined to drop common.mustCall()
. The more layers of stuff added to the test, the harder it is to figure out what the test is actually testing.
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 agree with @Trott.
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.
FWIW fccc0bf landed now you have common.mustCallAtLeast
}); | ||
|
||
// it would be nice if this worked: | ||
res.on('data', common.mustCall()); |
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.
Same comment 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.
Maybe replace with the longer but more explicit:
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', common.mustCall(() => {
assert.strictEqual(data, 'Part of my res.');
}));
This way it verifies all of these:
- the
data
callback is called at least once - the
data
callback is sent the expected value(s) - the
'end
callback is only fired after thedata
callback(s)
@@ -107,7 +107,8 @@ function check(tests) { | |||
const test = tests[0]; | |||
let server; | |||
if (test) { | |||
server = http.createServer(serverHandler).listen(0, '127.0.0.1', client); | |||
server = http.createServer(serverHandler) | |||
.listen(0, '127.0.0.1', common.mustCall(client)); |
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.
/s/127.0.0.1/common.localhostIPv4/
c.write(request_generator()); | ||
}); | ||
c.on('connect', common.mustCall(() => c.write(request_generator()))); | ||
c.on('data', common.mustCall((chunk) => server_response += chunk)); |
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.
common.mustCall()
takes an expected:int
as second argument.
I'll write a PR to have it expect '+'
as "more than zero".
Closing in favor of #14315 |
Minor refactoring in a number of http tests. I've been going through an auditing the existing http tests to identify which we will need equivalents for on the http2 implementation and spotted a number of cleanups that could be made.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
tests (http)