node/test/parallel/test-cluster-worker-init.js
Rich Trott 082cc8d6d8 test: remove unnecessary assignments
common.js needs to be loaded in all tests so that there is checking
for variable leaks and possibly other things. However, it does not
need to be assigned to a variable if nothing in common.js is referred
to elsewhere in the test.

PR-URL: https://github.com/nodejs/node/pull/4408
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-12-26 18:00:02 -08:00

33 lines
743 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
require('../common');
var assert = require('assert');
var cluster = require('cluster');
var msg = 'foo';
if (cluster.isMaster) {
var worker = cluster.fork();
var timer = setTimeout(function() {
assert(false, 'message not received');
}, 5000);
timer.unref();
worker.on('message', function(message) {
assert(message, 'did not receive expected message');
worker.disconnect();
});
worker.on('online', function() {
worker.send(msg);
});
} else {
// GH #7998
cluster.worker.on('message', function(message) {
process.send(message === msg);
});
}