-
Notifications
You must be signed in to change notification settings - Fork 29.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: remove duplicate test about warning in lib/net.js #41307
Conversation
These tests are not quite the same. The test you left makes sure that the warning is emitted on the first call. The test you deleted makes sure that the warning is emitted only once even when the API is called twice. They can certainly be consolidated into a single test, but they do not quite test the same things. |
@Trott Thanks for your comment! Based on your comment, I think it is |
test/parallel/test-net-server-simultaneous-accepts-produce-warning-once.js
Show resolved
Hide resolved
I've added some suggestions to try to make sure that the warning is called on the first invocation of the API and not on the second. (The way the test is written right now, I think it only checks that the warning is raised once but does not confirm it was the first call and not the second call. That's fine if the other test exists because the other tests confirms the warning is emitted on the first call. But if we're removing that other test, then maybe we should check that here too.) |
Thank you for your smart solution! |
6b9fa28
to
28db916
Compare
28db916
to
7fa3e4e
Compare
process.on('warning', mustCall(() => { | ||
process.on('warning', mustNotCall()); | ||
})); |
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.
nit: this could be simplified as mustCall
will check that the callback is only invoked once. We can also explicitly provide the number of calls we are expecting so it's clearer:
process.on('warning', mustCall(() => { | |
process.on('warning', mustNotCall()); | |
})); | |
process.on('warning', mustCall(1)); |
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.
@aduh95 Your suggestion is simpler, but is slightly more permissive than the code in this PR. The code in this PR guarantees that the first call of the API results in a warning and the second call does not. The change you suggest here will still result in a passing test if the first call does not result in a warning and the second one does. Admittedly, that's an edge case that is unlikely to happen. But I have a slight preference for the stricter checking 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.
I don’t see how, the current code checks the 'warning'
event is emitted once, but I don’t think it can know what API call triggered it either 🤔
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 see how, the current code checks the
'warning'
event is emitted once, but I don’t think it can know what API call triggered it either 🤔
Current code in master branch tests it by having two separate tests that are nearly identical. One test only calls the API once and makes sure that the warning is emitted once. The other test calls the API twice and makes sure that the warning is emitted once. Alone, that second test doesn't confirm that the warning happens on the first API call, but in combination with the first test, that is effectively checked.
This PR consolidates those two tests into a single test.
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.
Oh, wait, or are you suggesting that there will be a problem if something else (like --pending-deprecations
) causes warnings? Yeah, that's a valid concern and one we should address....
I'm wondering if we're actually best off just having two tests. :-D
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.
@kuriyosh How would you feel about restoring both tests and adding a short comment in each one explaining why there are two different-but-very-similar tests?
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.
In my understanding, the discussed concern is that this test fails if other warnings occur in a second call. (Please point me out if I'm wrong here.) I agree that we need to run test-net-deprecated-setsimultaneousaccepts.js
to make sure that _setSimultaneousAccepts()
does not emit other warnings.
On the other hand, test-net-server-simultaneous-accepts-produce-warning-once.js
in master branch does not check whether if _setSimultaneousAccepts()
emit DEP0121
in a second call. That test can be passed if second calling _setSimultaneousAccepts()
emit DEP0121
because of the behavior of expectsWarning().
So, I think the change of test-net-server-simultaneous-accepts-produce-warning-once.js
in this PR is needed.
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.
On the other hand,
test-net-server-simultaneous-accepts-produce-warning-once.js
in master branch does not check whether if_setSimultaneousAccepts()
emitDEP0121
in a second call.
It does check. expectsWarning()
will fail if it receives the warning more than once.
This exits with a failure status:
const {expectWarning} = require('./test/common');
expectWarning('foo', 'foo', 'foo');
This exits with success status:
const {expectWarning} = require('./test/common');
expectWarning('foo', 'foo', 'foo');
process.emitWarning('foo', 'foo', 'foo');
And this exits with a failure status again:
const {expectWarning} = require('./test/common');
expectWarning('foo', 'foo', 'foo');
process.emitWarning('foo', 'foo', 'foo');
process.emitWarning('foo', 'foo', 'foo');
One thing I notice while running these tests is that the error message is not great on that last example because const [ message, code ] = expected.shift();
(in test/common/index.js
) does not accommodate the possibility that expected
is an empty array and expected.shift()
returns undefined
:
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
So that's probably worth fixing.
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.
So that's probably worth fixing.
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.
Sorry, I misunderstood the behavior of expectWarning
...
I totally agree on having two separate tests.
I have committed for adding comment in these test codes.
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.
Blocking for the moment on https://github.com/nodejs/node/pull/41307/files#r775147880.
// This test checks that `_setSimultaneousAccepts` emit DEP0121 warning. | ||
// Ref test-net-server-simultaneous-accepts-produce-warning-once.js |
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 test checks that `_setSimultaneousAccepts` emit DEP0121 warning. | |
// Ref test-net-server-simultaneous-accepts-produce-warning-once.js | |
// Test that DEP0121 is emitted on the first call of _setSimultaneousAccepts(). |
test/parallel/test-net-server-simultaneous-accepts-produce-warning-once.js
Outdated
Show resolved
Hide resolved
I don't see a label for this but the commit queue should not be used to land this because the commit message for the first commit in this PR is no longer accurate. (@kuriyosh If you want to force-push an updated commit message, or even squash the four commits here into a single commit, that would be great. But if not, it's no big deal for someone to do it when landing this.) |
PR-URL: #41307 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #41307 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#41307 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #41307 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
test-net-server-simultaneous-accepts-produce-warning-once.js
test a same code astest-net-deprecated-setsimultaneousaccepts.js
.So I remove
test-net-server-simultaneous-accepts-produce-warning-once.js
.before coverage:
https://coverage.nodejs.org/coverage-895c3d937ea74faa/lib/net.js.html#L1761
after coverage: