0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-cluster-send-handle-twice.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

36 lines
1022 B
JavaScript

// Testing to send an handle twice to the parent process.
var common = require('../common');
var assert = require('assert');
var cluster = require('cluster');
var net = require('net');
var workers = {
toStart: 1
};
if (cluster.isMaster) {
for (var i = 0; i < workers.toStart; ++i) {
var worker = cluster.fork();
worker.on('exit', function(code, signal) {
assert.equal(code, 0, 'Worker exited with an error code');
assert(!signal, 'Worker exited by a signal');
});
}
} else {
var server = net.createServer(function(socket) {
process.send('send-handle-1', socket);
process.send('send-handle-2', socket);
});
server.listen(common.PORT, function() {
var client = net.connect({ host: 'localhost', port: common.PORT });
client.on('close', function() { cluster.worker.disconnect(); });
setTimeout(function() { client.end(); }, 50);
}).on('error', function(e) {
console.error(e);
assert(false, 'server.listen failed');
cluster.worker.disconnect();
});
}