mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
Backport-PR-URL: https://github.com/nodejs/node/pull/19120 PR-URL: https://github.com/nodejs/node/pull/17924 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
29 lines
731 B
JavaScript
29 lines
731 B
JavaScript
'use strict';
|
|
// test-cluster-worker-init.js
|
|
// verifies that, when a child process is forked, the cluster.worker
|
|
// object can receive messages as expected
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const msg = 'foo';
|
|
|
|
if (cluster.isMaster) {
|
|
const worker = cluster.fork();
|
|
|
|
worker.on('message', common.mustCall((message) => {
|
|
assert.strictEqual(message, true);
|
|
const w = worker.disconnect();
|
|
assert.strictEqual(worker, w);
|
|
}));
|
|
|
|
worker.on('online', () => {
|
|
worker.send(msg);
|
|
});
|
|
} else {
|
|
// https://github.com/nodejs/node-v0.x-archive/issues/7998
|
|
cluster.worker.on('message', (message) => {
|
|
process.send(message === msg);
|
|
});
|
|
}
|