-
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
refactor test-http-exceptions
file to use countdown
#17199
Conversation
const http = require('http'); | ||
const NUMBER_OF_EXCEPTIONS = 4; | ||
const countdown = new Countdown(NUMBER_OF_EXCEPTIONS, () => process.exit(0)); |
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 should be wrapped in common.mustCall
, also should the listener of process.on('uncaughtException')
and server.listen
This kind of reminds me: should we wrap the cb in common.mustCall
in the countdown module by default? @jasnell
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.
should we wrap the cb in
common.mustCall
in the countdown module by default?
Yeah, I've been thinking the same thing. It would be worthwhile I think
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.
Come to think of it, maybe this test does not need the countdown module and can just wrap the process.on('uncaughtException')
listener in common.mustCall(..., NUMBER_OF_EXCEPTIONS)
, because every expected action is the same. The countdown module seems to be more suitable for actions that vary.
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.
@joyeecheung unless i am overlooking something; I didn't wrap it in a mustCall
since not invoking the callback will result in a timeout and hence a failure in the test anyways, but adding it does not hurt as well.
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.
If you do go with this (and I'm with @joyeecheung that this maybe doesn't need Countdown
): Can you please wrap process.exit(0)
in {
and }
?
Without {
and }
, then the result of process.exit(0)
is the return value of the function. That function shouldn't have a return value.
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.
@Trott process.exit()
terminates the process synchronously, so the return value will not get passed back from the invocation, so it does not really matter if you pass an explicit return or not. I'll do it anyways for convention.
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.
Regarding wrapping the countdown with a mustCall, i think its a good idea to decide soon before contributors start implementing more refactors
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 in general, use common.mustCall
if the code calling countdown.dec()
is always the same, and use countdown
if the caller would be different. That way the code is cleaner. If we are trying to make the code cleaner by using countdown
, then I see no reason not to make it even cleaner with 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.
Also...can we implement common.mustCall
on top of countdown
?
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.
@joyeecheung i have implemented mustCall
on top of countdown, but im not sure i fully understand your suggestion about replacing countdown
with mustCall
process.on('uncaughtException',
common.mustCall(onUncaughtException, NUMBER_OF_EXCEPTIONS)
);
however how are we going to tell the code to process.exit(0)
? i cant see that happening without a counter
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
const http = require('http'); | ||
const NUMBER_OF_EXCEPTIONS = 4; | ||
const countdown = new Countdown(NUMBER_OF_EXCEPTIONS, () => { | ||
process.exit(0); |
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 this should be server.close
instead? (of course this line would need to be placed after the server creation)
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.
@joyeecheung calling server.close()
does not close the node process for some reason. resulting in a --- TIMEOUT ---
in the tests. These are just refactors, and the initial code also calls process.exit
. What do you suggest here?
ping @Bamieh |
pong @maclover7 |
@Bamieh this needs a rebase. |
Closing due to no further progress. @Bamieh please feel free to reopen if you would like to continue working on it (it only needs a rebase). |
test-http-exceptions
to use countdown, as per issue [Tracking issue] Converting tests to use Countdown #17169common.mustCall
to thecountdown
callback, since the user will always want this function to be called, and it must fail if the user fails to decrease the counter to 0.common.mustCall
functions around theCountdown
callbacks in all the tests.countdown
to test that a mustCall is in place.common.md
docs to inform thecountdown
users that the test will fail if the countdown callback was not called.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test