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
13 changes: 7 additions & 6 deletions test/parallel/test-cluster-dgram-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ function master() {

// Start listening on a socket.
const socket = dgram.createSocket('udp4');
socket.bind(common.PORT);
socket.bind(0, () => {
const port = socket.address().port;
// Fork workers.
for (let i = 0; i < NUM_WORKERS; i++)
cluster.fork({BOUNDPORT: port});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

});

// Disconnect workers when the expected number of messages have been
// received.
Expand All @@ -61,10 +66,6 @@ function master() {
cluster.disconnect();
}
}, NUM_WORKERS * PACKETS_PER_WORKER));

// Fork workers.
for (let i = 0; i < NUM_WORKERS; i++)
cluster.fork();
}


Expand All @@ -81,7 +82,7 @@ function worker() {
// There is no guarantee that a sent dgram packet will be received so keep
// sending until disconnect.
const interval = setInterval(() => {
socket.send(buf, 0, buf.length, common.PORT, '127.0.0.1');
socket.send(buf, 0, buf.length, process.env.BOUNDPORT, '127.0.0.1');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be worthwhile adding an assert to make sure process.env.BOUNDPORT is set

}, 1);

cluster.worker.on('disconnect', () => {
Expand Down