-
Notifications
You must be signed in to change notification settings - Fork 30k
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: refactor test for net listen on fd0 #10025
Conversation
}); | ||
process.on('exit', function() { | ||
assert(gotError instanceof Error); | ||
}); |
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 think you could get rid of the exit
listener if you assert in the error
callback that e.code can only be EINVAL
or ENOTSOCK
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.
@santigimeno do you suggest to do something like:
.on('error', common.mustCall(function(e) {
switch (e.code) {
case 'EINVAL':
case 'ENOTSOCK':
assert(e instanceof Error);
break;
}
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 a suggestion
|
||
var gotError = false; | ||
// this should fail with an async EINVAL error, not throw an exception |
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.
Can you capitalize and punctuate the comment please.
a3d0886
to
dab7b0c
Compare
Rebased with suggestions from @cjihrig and @santigimeno |
switch (e.code) { | ||
case 'EINVAL': | ||
case 'ENOTSOCK': | ||
assert(e instanceof Error); |
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 seems incorrect to me. The previous behavior ran the assertion no matter what. The new behavior guarantees that an error is emitted, but not that it is the correct type. What if you just did:
assert(e instanceof Error);
assert(['EINVAL', 'ENOTSOCK'].includes(e.code));
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.
@cjihrig way better, I like it, just rebased with your suggestions
Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler
dab7b0c
to
7255098
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 pending CI
Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler PR-URL: #10025 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 1d766b8. Thank you for the PR and for participating in the code-and-learn! |
Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler PR-URL: #10025 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler PR-URL: nodejs#10025 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler PR-URL: nodejs#10025 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Replace var to const/let, use common.mustCall on callbacks and move process.on('exit') to the .on('error') handler PR-URL: #10025 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
test, net
Description of change
Replace var to const/let, use common.mustCall on callbacks and move
process.on('exit') to the .on('error') handler