mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 20:31:36 +00:00

There are several places in the cluster module where a version of process.send() is called, but the result is swallowed. Most of these cases are internal, but Worker.prototype.send(), which is publicly documented, also suffers from this problem. This commit exposes the return value to facilitate better error handling, and bring Worker.prototype.send() into compliance with the documentation. PR-URL: https://github.com/nodejs/node/pull/6998 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var cluster = require('cluster');
|
|
|
|
if (cluster.isWorker) {
|
|
const result = cluster.worker.send({
|
|
prop: process.env['cluster_test_prop'],
|
|
overwrite: process.env['cluster_test_overwrite']
|
|
});
|
|
|
|
assert.strictEqual(result, true);
|
|
} else if (cluster.isMaster) {
|
|
|
|
var checks = {
|
|
using: false,
|
|
overwrite: false
|
|
};
|
|
|
|
// To check that the cluster extend on the process.env we will overwrite a
|
|
// property
|
|
process.env['cluster_test_overwrite'] = 'old';
|
|
|
|
// Fork worker
|
|
var worker = cluster.fork({
|
|
'cluster_test_prop': 'custom',
|
|
'cluster_test_overwrite': 'new'
|
|
});
|
|
|
|
// Checks worker env
|
|
worker.on('message', function(data) {
|
|
checks.using = (data.prop === 'custom');
|
|
checks.overwrite = (data.overwrite === 'new');
|
|
process.exit(0);
|
|
});
|
|
|
|
process.once('exit', function() {
|
|
assert.ok(checks.using, 'The worker did not receive the correct env.');
|
|
assert.ok(checks.overwrite, 'The custom environment did not overwrite ' +
|
|
'the existing environment.');
|
|
});
|
|
|
|
}
|