Skip to content

Commit 5d3c64f

Browse files
santigimenoMyles Borins
authored and
Myles Borins
committed
test: fix cluster-disconnect-handles flakiness
Sometimes the test was timing out because the worker process remained stuck in the breakpoint and didn't exit. This could happen because the continue was sent before the breakpoint was set. If that's the case, with this change, a new continue command is sent so the worker process can end. PR-URL: #4009 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 2bb9c1c commit 5d3c64f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

test/parallel/test-cluster-disconnect-handles.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ if (cluster.isMaster) {
3333
worker.on('message', common.mustCall(message => {
3434
assert.strictEqual(Array.isArray(message), true);
3535
assert.strictEqual(message[0], 'listening');
36+
let continueRecv = false;
3637
const address = message[1];
3738
const host = address.address;
3839
const debugClient = net.connect({ host, port: common.PORT });
@@ -41,13 +42,25 @@ if (cluster.isMaster) {
4142
debugClient.on('data', data => protocol.execute(data));
4243
debugClient.once('connect', common.mustCall(() => {
4344
protocol.onResponse = common.mustCall(res => {
44-
protocol.onResponse = () => {};
45+
protocol.onResponse = (res) => {
46+
// It can happen that the first continue was sent before the break
47+
// event was received. If that's the case, send also a continue from
48+
// here so the worker exits
49+
if (res.body.command === 'continue') {
50+
continueRecv = true;
51+
} else if (res.body.event === 'break' && continueRecv) {
52+
const req = protocol.serialize({ command: 'continue' });
53+
debugClient.write(req);
54+
}
55+
};
4556
const conn = net.connect({ host, port: address.port });
4657
conn.once('connect', common.mustCall(() => {
4758
conn.destroy();
4859
assert.notDeepStrictEqual(handles, {});
4960
worker.disconnect();
5061
assert.deepStrictEqual(handles, {});
62+
// Always send the continue, as the break event might have already
63+
// been received.
5164
const req = protocol.serialize({ command: 'continue' });
5265
debugClient.write(req);
5366
}));

0 commit comments

Comments
 (0)