-
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: test clusters --inspect-brk and --debug-brk #11471
Conversation
This test ensures that flag --inspect-brk and --debug-brk works properly for clusters.
setTimeout(() => { | ||
worker.removeListener('exit', fail); | ||
worker.kill(); | ||
}, 2000); |
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 looks like a recipe for a flaky test, I'd suggest waiting until the debug/inspect TCP port is open/can be connected to
This test ensures that flag --inspect-brk and --debug-brk works properly for clusters.
const debuggerPort = common.PORT; | ||
const script = common.fixturesDir + '/empty.js'; | ||
|
||
function fail() { |
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.
Instead of this, please use common.fail()
or common.mustNotCall()
, which are designed to do essentially this same thing without cluttering up the tests.
]; | ||
|
||
process.on('exit', function() { | ||
workers.map((wk) => { |
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 want forEach()
, not map()
.
|
||
process.on('exit', function() { | ||
workers.map((wk) => { | ||
assert.equal(wk.process.killed, true); |
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.
Please use assert.strictEqual()
.
|
||
worker.on('exit', fail); | ||
|
||
let socket = net.connect(debuggerPort + offset, () => { |
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 add common.mustCall()
around the callback.
|
||
let socket = net.connect(debuggerPort + offset, () => { | ||
socket.end(); | ||
worker.removeListener('exit', fail); |
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.
Instead of having this fail()
function and the process.on('exit', ...)
block, it might be better to use the cluster worker exit
event and check the exit code and signal to make sure it was killed by signal (there is an example in the docs).
- wrap callbacks in `common.mustCall`. - check exit code of the cluster worker process instead of checking from main process. - other misc. corrections.
Thanks @cjihrig for your comments. I have updated accordingly. |
assert.strictEqual(signal, 'SIGTERM'); | ||
})); | ||
|
||
let socket = net.connect(debuggerPort + offset, 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.
I would wrap this code inside of a worker.on('online', common.mustCall(...))
just to be sure that the worker is ready for the connection.
fork(3, [`--debug-brk`, script]); | ||
fork(4, [`--debug-brk=${debuggerPort}`, script]); | ||
|
||
process.on('exit', (code, signal) => { |
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 block can be dropped completely.
Thanks @cjihrig I have updated. |
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: https://ci.nodejs.org/job/node-test-pull-request/6821/
@liusy182 it looks like there are some CI failures. |
Remove the check of exit code equals null because on some machines the exit code can be 0
Looks like a few failures on centos |
It seems like this got fixed somewhere else in the meanwhile. Therefore I am going to close this. @liusy182 I am very sorry your PR could not land! |
This test ensures that flag --inspect-brk and --debug-brk works
properly for clusters.
Issue #11420
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test