Browse Source

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: https://github.com/nodejs/node/pull/14780
Fixes: https://github.com/nodejs/node/issues/14747
Reviewed-By: Anna Henningsen <anna@addaleax.net>
v6
Rich Trott 7 years ago
parent
commit
28a47aa1bb
  1. 20
      test/parallel/test-cluster-send-handle-large-payload.js

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

@ -1,5 +1,6 @@
'use strict'; 'use strict';
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cluster = require('cluster'); const cluster = require('cluster');
const net = require('net'); const net = require('net');
@ -9,7 +10,7 @@ const payload = 'a'.repeat(800004);
if (cluster.isMaster) { if (cluster.isMaster) {
const server = net.createServer(); const server = net.createServer();
server.on('connection', common.mustCall((socket) => socket.unref())); server.on('connection', common.mustCall((socket) => { socket.unref(); }));
const worker = cluster.fork(); const worker = cluster.fork();
worker.on('message', common.mustCall(({ payload: received }, handle) => { worker.on('message', common.mustCall(({ payload: received }, handle) => {
@ -31,10 +32,23 @@ if (cluster.isMaster) {
process.on('message', common.mustCall(({ payload: received }, handle) => { process.on('message', common.mustCall(({ payload: received }, handle) => {
assert.strictEqual(payload, received); assert.strictEqual(payload, received);
assert(handle instanceof net.Socket); assert(handle instanceof net.Socket);
process.send({ payload }, handle);
// 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.
//
// Refs: https://github.com/nodejs/node/issues/14747
if (common.isOSX)
setTimeout(() => { process.send({ payload }, handle); }, 1000);
else
process.send({ payload }, handle);
// Prepare for a clean exit. // Prepare for a clean exit.
process.channel.unref(); process.channel.unref();
handle.unref();
})); }));
} }

Loading…
Cancel
Save