Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

julianduque
Copy link
Contributor

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected 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

@julianduque julianduque added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Dec 1, 2016
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 1, 2016
@julianduque julianduque added the net Issues and PRs related to the net subsystem. label Dec 1, 2016
@imyller imyller removed the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Dec 1, 2016
@julianduque julianduque added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Dec 1, 2016
});
process.on('exit', function() {
assert(gotError instanceof Error);
});
Copy link
Member

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

Copy link
Contributor Author

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;
    }

Copy link
Member

@santigimeno santigimeno left a 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
Copy link
Contributor

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.

@julianduque
Copy link
Contributor Author

Rebased with suggestions from @cjihrig and @santigimeno

@Fishrock123
Copy link
Contributor

switch (e.code) {
case 'EINVAL':
case 'ENOTSOCK':
assert(e instanceof Error);
Copy link
Contributor

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));

Copy link
Contributor Author

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
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending CI

@gibfahn
Copy link
Member

gibfahn commented Dec 5, 2016

jasnell pushed a commit that referenced this pull request Dec 5, 2016
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 <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@jasnell
Copy link
Member

jasnell commented Dec 5, 2016

Landed in 1d766b8. Thank you for the PR and for participating in the code-and-learn!

@jasnell jasnell closed this Dec 5, 2016
@julianduque julianduque deleted the test-net-listen-fd0 branch December 6, 2016 00:58
Fishrock123 pushed a commit that referenced this pull request Dec 6, 2016
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 <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to addaleax/node that referenced this pull request Dec 8, 2016
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 <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
jmdarling pushed a commit to jmdarling/node that referenced this pull request Dec 8, 2016
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 <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this pull request Dec 21, 2016
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 <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. net Issues and PRs related to the net subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants