-
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
Changes from 3 commits
63e78ed
e2c86af
c6c73d2
e7b1975
ab85649
e1ccdcb
c39b078
9f9a725
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
// Flags: --inspect={PORT} | ||
// This test ensures that flag --inspect-brk and --debug-brk works properly | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const net = require('net'); | ||
|
||
const debuggerPort = common.PORT; | ||
const script = common.fixturesDir + '/empty.js'; | ||
|
||
function fail() { | ||
assert(0); // `node --debug-brk script.js` should not quit | ||
} | ||
|
||
if (cluster.isMaster) { | ||
|
||
function fork(offset, execArgv) { | ||
cluster.setupMaster(execArgv); | ||
let worker = cluster.fork(); | ||
|
||
worker.on('exit', fail); | ||
|
||
let socket = net.connect(debuggerPort + offset, () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add |
||
socket.end(); | ||
worker.removeListener('exit', fail); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of having this |
||
worker.kill(); | ||
}); | ||
|
||
return worker; | ||
} | ||
|
||
assert.strictEqual(process.debugPort, debuggerPort); | ||
|
||
let workers = [ | ||
fork(1, [`--inspect-brk`, script]), | ||
fork(2, [`--inspect-brk=${debuggerPort}`, script]), | ||
fork(3, [`--debug-brk`, script]), | ||
fork(4, [`--debug-brk=${debuggerPort}`, script]) | ||
]; | ||
|
||
process.on('exit', function() { | ||
workers.map((wk) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want |
||
assert.equal(wk.process.killed, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
}); | ||
}); | ||
} |
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()
orcommon.mustNotCall()
, which are designed to do essentially this same thing without cluttering up the tests.