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 3 commits
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
47 changes: 47 additions & 0 deletions test/parallel/test-cluster-inspector-debug-brk.js
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() {
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(offset, execArgv) {
cluster.setupMaster(execArgv);
let worker = cluster.fork();

worker.on('exit', fail);

let socket = net.connect(debuggerPort + offset, () => {
Copy link
Contributor

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.

socket.end();
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();
});

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

});
});
}