mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 23:10:15 +00:00

- `var` --> `const` as applicable - `assert.equal` --> `assert.strictEqual` - `assert(false, ..)` --> `common.fail()` - `common.mustCall` for functions that need to be called exactly once - modified an `assert(!signal, 'Worker exited by a signal');` call to `assert.strictEqual(signal, null);` call as that made more sense PR-URL: https://github.com/nodejs/node/pull/10049 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
'use strict';
|
|
// Testing to send an handle twice to the parent process.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const net = require('net');
|
|
|
|
const workers = {
|
|
toStart: 1
|
|
};
|
|
|
|
if (cluster.isMaster) {
|
|
for (let i = 0; i < workers.toStart; ++i) {
|
|
const worker = cluster.fork();
|
|
worker.on('exit', common.mustCall(function(code, signal) {
|
|
assert.strictEqual(code, 0, 'Worker exited with an error code');
|
|
assert.strictEqual(signal, null, 'Worker exited by a signal');
|
|
}));
|
|
}
|
|
} else {
|
|
const server = net.createServer(function(socket) {
|
|
process.send('send-handle-1', socket);
|
|
process.send('send-handle-2', socket);
|
|
});
|
|
|
|
server.listen(common.PORT, function() {
|
|
const client = net.connect({ host: 'localhost', port: common.PORT });
|
|
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
|
|
setTimeout(function() { client.end(); }, 50);
|
|
}).on('error', function(e) {
|
|
console.error(e);
|
|
common.fail('server.listen failed');
|
|
cluster.worker.disconnect();
|
|
});
|
|
}
|