-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
test: fix global.PORT in dgram-cluster-test-1 #12491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Refs: #12376
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| }); | ||
| } | ||
|
|
||
| if (common.isWindows) { | ||
| common.skip('dgram clustering is currently not supported ' + | ||
| 'on windows.'); | ||
| 'on windows.'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated whitespace change?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm apologize, It's not related.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks again, I'm definitely planning to do more..
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. הוא מתכוון שכדאי לתקן את זה 😉
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fixing it now..
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(() => { | ||
|
|
@@ -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() { | ||
|
|
@@ -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); | ||
| })); | ||
| } | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.