Skip to content
Closed
Changes from 1 commit
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
Next Next commit
test: fix global.PORT in dgram-cluster-test-1
Refs: #12376
  • Loading branch information
zivkaziv committed Apr 18, 2017
commit af7cd7274c3c155497fa241a43bb2da1ba63f5fb
35 changes: 25 additions & 10 deletions test/parallel/test-cluster-dgram-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,37 @@ const assert = require('assert');
const cluster = require('cluster');
const dgram = require('dgram');

function getPort(cb) {
const s = dgram.createSocket({ type: 'udp4', reuseAddr: true });
s.bind(0, () => {
const port = s.address().port;
s.close();
cb(null, port);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By the time this port is used by the test, there is a possibility that this would be assigned to someother process by the operating system.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or Am I missing something here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This port assignment was relay on the suggestion of @benjamingr in
#12426 (comment)

Maybe the right solution is to close this port only in the end of the test.

});
}

if (common.isWindows) {
common.skip('dgram clustering is currently not supported ' +
'on windows.');
'on windows.');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unrelated whitespace change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm apologize, It's not related.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No worries. Thanks for taking the time to do this PR, and I hope the duplicate PR thing won't discourage you from doing more!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks again, I'm definitely planning to do more..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

הוא מתכוון שכדאי לתקן את זה 😉
אתה יכול לשנות את הקומיט האחרון ועשות פורס-פוש, או להוסיף עוד קומיט.

Copy link
Copy Markdown
Member

@benjamingr benjamingr Apr 19, 2017

Choose a reason for hiding this comment

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

@refack please stick to English in comments, thanks :) (so people are not excluded from the discussion). We have the Hebrew locale repo if you'd like to participate in translation and localization efforts.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm fixing it now..
Thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hebrew re: #12491 (comment)

return;
}

if (cluster.isMaster)
master();
else
// We are creating unique port only for the in the master cluster
if (cluster.isMaster) {
getPort((info, port) => {
master(port);
});
} else {
worker();
}


function master() {
function master(port) {
let listening = 0;

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

// Wait until all workers are listening.
cluster.on('listening', common.mustCall(() => {
Expand All @@ -60,7 +72,7 @@ function master() {
doSend();

function doSend() {
socket.send(buf, 0, buf.length, common.PORT, '127.0.0.1', afterSend);
socket.send(buf, 0, buf.length, port, '127.0.0.1', afterSend);
}

function afterSend() {
Expand Down Expand Up @@ -106,10 +118,13 @@ function worker() {

// Every 10 messages, notify the master.
if (received === PACKETS_PER_WORKER) {
process.send({received: received});
process.send({ received: received });
socket.close();
}
}, PACKETS_PER_WORKER));

socket.bind(common.PORT);
// We are getting the PORT through the process
// message in the master process => cluster.fork().send(port);
process.on('message', common.mustCall((port, info) => {
socket.bind(port);
}));
}