Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions test/parallel/test-dgram-bind-shared-ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const cluster = require('cluster');
const dgram = require('dgram');

if (cluster.isMaster) {
const worker1 = cluster.fork();
const worker1 = cluster.fork({
SOCKET1: 0,
SOCKET2: 0
});

if (common.isWindows) {
const checkErrType = (er) => {
Expand All @@ -38,16 +41,21 @@ if (cluster.isMaster) {
return;
}

worker1.on('message', (msg) => {
assert.strictEqual(msg, 'success');
const worker2 = cluster.fork();
worker1.on('message', common.mustCall((msg) => {
assert(msg.socketPort1);
assert(msg.socketPort2);

const worker2 = cluster.fork({
SOCKET1: msg.socketPort1,
SOCKET2: msg.socketPort2
});

worker2.on('message', (msg) => {
worker2.on('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'socket2:EADDRINUSE');
worker1.kill();
worker2.kill();
});
});
}));
}));
} else {
const socket1 = dgram.createSocket('udp4', common.noop);
const socket2 = dgram.createSocket('udp4', common.noop);
Expand All @@ -64,12 +72,23 @@ if (cluster.isMaster) {

socket1.bind({
address: 'localhost',
port: common.PORT,
port: 0,
exclusive: false
}, () => {
socket2.bind({ port: common.PORT + 1, exclusive: true }, () => {
}, common.mustCall(() => {
if (process.env.SOCKET1 !== '0') {
assert.strictEqual(process.env.SOCKET1, '' + socket1.address().port);
}

socket2.bind({
address: 'localhost',
port: process.env.SOCKET2,
exclusive: true
}, common.mustCall(() => {
// the first worker should succeed
process.send('success');
});
});
process.send({
socketPort1: socket1.address().port,
socketPort2: socket2.address().port
});
}));
}));
}