Skip to content

Commit 7f02c36

Browse files
TrottMylesBorins
authored andcommitted
test: fix test-cluster-send-handle-large-payload
On macOS, the parent process might not receive a message if it is sent to soon, and then subsequent messages are also sometimes not received. (Is this a bug or expected operating system behavior like the way a file watcher is returned before it's actually watching the file system on/ macOS?) Send a second message after a delay on macOS. While at it, minor refactoring to the test: * Blank line after loading `common` module per test-writing guide * Wrap arrow function in braces where implicit return is not needed * Remove unnecessary unref in subprocess PR-URL: #14780 Fixes: #14747 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 136eea4 commit 7f02c36

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/parallel/test-cluster-send-handle-large-payload.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common');
3+
34
const assert = require('assert');
45
const cluster = require('cluster');
56
const net = require('net');
@@ -9,7 +10,7 @@ const payload = 'a'.repeat(800004);
910
if (cluster.isMaster) {
1011
const server = net.createServer();
1112

12-
server.on('connection', common.mustCall((socket) => socket.unref()));
13+
server.on('connection', common.mustCall((socket) => { socket.unref(); }));
1314

1415
const worker = cluster.fork();
1516
worker.on('message', common.mustCall(({ payload: received }, handle) => {
@@ -31,10 +32,23 @@ if (cluster.isMaster) {
3132
process.on('message', common.mustCall(({ payload: received }, handle) => {
3233
assert.strictEqual(payload, received);
3334
assert(handle instanceof net.Socket);
34-
process.send({ payload }, handle);
35+
36+
// On macOS, the parent process might not receive a message if it is sent
37+
// to soon, and then subsequent messages are also sometimes not received.
38+
//
39+
// (Is this a bug or expected operating system behavior like the way a file
40+
// watcher is returned before it's actually watching the file system on
41+
// macOS?)
42+
//
43+
// Send a second message after a delay on macOS.
44+
//
45+
// Refs: https://github.com/nodejs/node/issues/14747
46+
if (common.isOSX)
47+
setTimeout(() => { process.send({ payload }, handle); }, 1000);
48+
else
49+
process.send({ payload }, handle);
3550

3651
// Prepare for a clean exit.
3752
process.channel.unref();
38-
handle.unref();
3953
}));
4054
}

0 commit comments

Comments
 (0)