-
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: refactor test-beforeexit-event #10121
Conversation
cda4900
to
48691c1
Compare
|
||
function tryTimer() { | ||
const tryTimer = () => { |
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.
Why is this necessary?
|
||
function tryListen() { | ||
const tryListen = () => { |
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 here, why is this necessary?
} | ||
}; | ||
|
||
process.on('beforeExit', () => { deaths++; }); |
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 we should just get rid of the revivals
and deaths
variables and just use common.mustCall()
with the expected number of calls.
faa9ace
to
0eddb09
Compare
} | ||
|
||
function beforeProcess() { | ||
console.log('before process'); |
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 better as before listener
?
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 thought we were trying to remove all logging in tests unless required by the 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.
Maybe but it just gets swallowed anyways?
The console.log
are definitely not required though so ¯\_(ツ)_/¯
assert.equal(3, revivals); | ||
process.on('exit', () => { | ||
common.mustCall(beforeExit, 4); | ||
common.mustCall(beforeProcess, 3); |
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.
That's not how this works. :)
You will need to wrap the callback that you want to call before using it (as in, the variables at lines 9-15 already need the wrappers). Then the exit
event listener can be removed.
cba9aff
to
3e3fe42
Compare
@Fishrock123 requested changes have been completed, any additional feedback would be much appreciated. Thanks:-) |
|
||
process.on('beforeExit', function() { deaths++; }); | ||
const beforeExit = 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.
This can just be:
process.on('beforeExit', common.mustCall(() => {}), 4);
this.close(); | ||
}) | ||
.on('error', (e) => { |
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 'error'
handler can be removed since node will already throw if there are no 'error'
handlers.
setImmediate(function() { | ||
revivals++; | ||
setImmediate(() => { | ||
beforeListener(); |
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.
What I had in mind instead of this is to wrap the enclosing function in common.mustCall()
, for example:
setImmediate(common.mustCall(() => {
process.once('beforeExit', common.mustCall(tryTimer));
}));
setTimeout(function() { | ||
console.log('timeout cb, do another once beforeExit'); | ||
revivals++; | ||
setTimeout(() => { |
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.
Similarly, this would instead be:
setTimeout(common.mustCall(() => {
process.once('beforeExit', common.mustCall(tryListen));
}));
process.once('beforeExit', tryListen); | ||
}, 1); | ||
} | ||
|
||
function tryListen() { | ||
console.log('create a server'); | ||
net.createServer() | ||
.listen(0) | ||
.on('listening', function() { |
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.
and this one would just be
.on('listening', common.mustCall(() => {
this.close();
}));
return; | ||
}, 3); | ||
|
||
process.on('beforeExit', beforeExit); | ||
|
||
process.once('beforeExit', tryImmediate); |
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 needs to be:
process.once('beforeExit', common.mustCall(tryImmediate));
29b7e97
to
8f8c63e
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 a little nit
}, 4); | ||
|
||
const beforeListener = common.mustCall(() => { | ||
return; |
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.
These can probably just be () => {}
|
||
process.on('beforeExit', function() { deaths++; }); | ||
const beforeExit = common.mustCall(() => {}, 4); |
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.
Now that I think about it, I think we can actually get rid of this separate check entirely by just adding a
process.on('beforeExit', common.mustCall(() => {}));
after the this.close()
in tryListen()
.
8f8c63e
to
5a9a898
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.
LGTM
CI clean except for failure on smartos which seems unrelated to this test. Opened #10166 to track that issue separately. |
@radelmann, one last thing before we land. We need your full name "Rob Adelmann" as the author for the commit. I could fix that as part of landing but probably better if you do this in your env and re-push. You should be able to change with: git commit --amend --author="Rob Adelmann [email protected]" and if you can also update your git config so that future commits also have your full name that would be good. |
Just for clarity, feel free to use the name and email address you would like your commits to be credited to (or indicate that just “adelmann” is actually exactly what you prefer). |
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener.
5a9a898
to
4b254d8
Compare
Landed in 8960383, thanks for the contribution! |
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: #10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: #10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: nodejs#10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: #10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: #10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- replaced var with const/let. - removed all console.log() statements. - removed deaths and revivals vars. - wrapped beforexit listener callbacks with common.mustCall(). - removed exit event listener. PR-URL: #10121 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
test
Description of change
var
withconst
orlet
.console.log()
statements.deaths
andrevivals
vars.beforexit
listener callbacks withcommon.mustCall()
.exit
event listener.