-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
test: replace port in cluster dgram reuse test #12901
Conversation
@@ -23,7 +23,7 @@ | |||
const common = require('../common'); | |||
const net = require('net'); | |||
|
|||
const conn = net.createConnection(common.PORT); | |||
const conn = net.createConnection(0); |
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.
Would net.connect()
work better 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.
Port 0 with connect()
or createConnection()
makes no sense, except perhaps for connections that will fail for other reasons already (in which case it should probably have a comment explaining that).
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.
(Which it looks like this one is expected to fail because there's nothing listening on the port. But then the issue is: Does this test still test the thing it was written to test? I don't know the answer to that.)
@@ -40,7 +40,7 @@ function test1() { | |||
}; | |||
|
|||
try { | |||
tls.connect(common.PORT); | |||
tls.connect(0); |
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.
Same: port 0 on connect()
makes no sense. Comment needed if this change is correct.
test/parallel/test-tls-connect.js
Outdated
@@ -37,7 +37,7 @@ const path = require('path'); | |||
const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')); | |||
const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')); | |||
|
|||
const options = {cert: cert, key: key, port: common.PORT}; | |||
const options = {cert: cert, key: key, port: 0}; |
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.
Same as other comments regarding connect()
and port 0.
test/parallel/test-tls-connect.js
Outdated
@@ -51,7 +51,7 @@ const path = require('path'); | |||
const conn = tls.connect({ | |||
cert: cert, | |||
key: key, | |||
port: common.PORT, | |||
port: 0, |
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.
Same as other comments regarding connect()
and port 0.
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.
I'm skeptical that the port 0 connect()
calls are still testing what they are supposed to test. At a minimum, they need a comment.
The comment, I'm trying to understand how to phrase it, please let me know if this is correct. If you use |
Let's say that
So changing |
Understood. What do you think would be a better solution. If you could help me I would really appreciate it. I'm on #node-dev. |
It requires a case-by-case analysis. In some cases, using port 0 will be fine. In others, moving to |
By the way, moving to |
@Trott Thanks for the direction, I will try to look a little closer at each test. |
I have shrunk this PR to just the first file. Might be better to go over those other tests separately. |
scope of PR has been reduced, eliminating my concerns
@@ -37,4 +37,4 @@ function close() { | |||
} | |||
|
|||
for (let i = 0; i < 2; i++) | |||
dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next); | |||
dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(0, next); |
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.
At a second glance, it seems that this will make the two sockets use two different ports which is not what we want here. Something like this should work.
diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js
index aed565a380..3e7868bc30 100644
--- a/test/parallel/test-cluster-dgram-reuse.js
+++ b/test/parallel/test-cluster-dgram-reuse.js
@@ -17,24 +17,22 @@ if (cluster.isMaster) {
return;
}
-const sockets = [];
-function next() {
- sockets.push(this);
- if (sockets.length !== 2)
- return;
-
- // Work around health check issue
- process.nextTick(() => {
- for (let i = 0; i < sockets.length; i++)
- sockets[i].close(close);
- });
-}
-
let waiting = 2;
function close() {
if (--waiting === 0)
cluster.worker.disconnect();
}
-for (let i = 0; i < 2; i++)
- dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next);
+const options = { type: 'udp4', reuseAddr: true };
+const socket1 = dgram.createSocket(options);
+const socket2 = dgram.createSocket(options);
+
+socket1.bind(0, () => {
+ socket2.bind(socket1.address().port, () => {
+ // Work around health check issue
+ process.nextTick(() => {
+ socket1.close(close);
+ socket2.close(close);
+ });
+ })
+});
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.
I will make the changes, thanks.
Replaced common.PORT with zero in the following test. test-cluster-dgram-reuse.js Refs: #12376
@lpinca All done, I made the edits. |
@nodejs/collaborators anyone else want to sign-off on this? |
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.
LGTM
Just for cross reference #13100 |
Landed in 6b1819c. |
Remove common.PORT from test-cluster-dgram-reuse to eliminate possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: #12901 Ref: #12376 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Remove common.PORT from test-cluster-dgram-reuse to eliminate possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: nodejs#12901 Ref: nodejs#12376 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Remove common.PORT from test-cluster-dgram-reuse to eliminate possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: #12901 Ref: #12376 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Replaced common.PORT with zero in the following test.
test-cluster-dgram-reuse.js
Refs: #12376
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test