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: improve cluster-disconnect-handles test #4084

Closed
Closed
Changes from all 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
24 changes: 22 additions & 2 deletions test/parallel/test-cluster-disconnect-handles.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cluster.schedulingPolicy = cluster.SCHED_RR;
// is to make sure the connection is still sitting in the master's
// pending handle queue.
if (cluster.isMaster) {
let isKilling = false;
const handles = require('internal/cluster').handles;
// FIXME(bnoordhuis) lib/cluster.js scans the execArgv arguments for
// debugger flags and renumbers any port numbers it sees starting
Expand Down Expand Up @@ -55,11 +56,30 @@ if (cluster.isMaster) {
}));
}));
process.on('exit', () => assert.deepStrictEqual(handles, {}));
process.on('uncaughtException', function(ex) {
// Make sure we clean up so as not to leave a stray worker process running
// if we encounter a connection or other error
if (!worker.isDead()) {
if (!isKilling) {
isKilling = true;
worker.once('exit', function() {
throw ex;
});
worker.process.kill();
}
return;
}
throw ex;
});
} else {
const server = net.createServer(socket => socket.pipe(socket));
server.listen(() => {
const cb = () => {
process.send(['listening', server.address()]);
debugger;
});
};
if (common.hasIPv6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... is this the only test that suffers from this problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, but this was the only one I personally saw that was causing this problem.

server.listen(cb);
else
server.listen(0, common.localhostIPv4, cb);
process.on('disconnect', process.exit);
}