mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
15164cebce
Doc deprecate isMaster and setupMaster in favor of isPrimary and setupPrimary. Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: https://github.com/nodejs/node/pull/36478 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Beth Griggs <bgriggs@redhat.com>
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// Regression test for https://github.com/nodejs/node/issues/13435
|
|
// Tests that `socket.server` is correctly set when a socket is sent to a worker
|
|
// and the `'connection'` event is emitted manually on an HTTP server.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cluster = require('cluster');
|
|
const http = require('http');
|
|
const net = require('net');
|
|
|
|
if (cluster.isPrimary) {
|
|
const worker = cluster.fork();
|
|
const server = net.createServer(common.mustCall((socket) => {
|
|
worker.send('socket', socket);
|
|
}));
|
|
|
|
worker.on('exit', common.mustCall((code) => {
|
|
assert.strictEqual(code, 0);
|
|
server.close();
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
net.createConnection(server.address().port);
|
|
}));
|
|
} else {
|
|
const server = http.createServer();
|
|
|
|
server.on('connection', common.mustCall((socket) => {
|
|
assert.strictEqual(socket.server, server);
|
|
socket.destroy();
|
|
cluster.worker.disconnect();
|
|
}));
|
|
|
|
process.on('message', common.mustCall((message, socket) => {
|
|
server.emit('connection', socket);
|
|
}));
|
|
}
|