Skip to content
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

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions test/parallel/test-cluster-inspector-debug-brk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';
// 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 script = common.fixturesDir + '/empty.js';

function fail() {
Copy link
Contributor

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.

assert(0); // `node --debug-brk script.js` should not quit
}

if (cluster.isMaster) {

function fork(execArgv) {
cluster.setupMaster({execArgv});
let worker = cluster.fork();

worker.on('exit', fail);

// give node time to start up the debugger
setTimeout(() => {
worker.removeListener('exit', fail);
Copy link
Contributor

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).

worker.kill();
}, 2000);
Copy link
Contributor

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


return worker;
}

let workers = [
fork([script, '--inspect-brk']),
fork([script, `--inspect-brk=5959`]),
fork([script, '--debug-brk']),
fork([script, `--debug-brk=9230`])
];

process.on('exit', function() {
workers.map((wk) => {
Copy link
Contributor

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().

assert.equal(wk.process.killed, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use assert.strictEqual().

});
});
}