Skip to content
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 dgram cd address empty test #12929

Closed
wants to merge 1 commit into from
Closed

test: replace port in dgram cd address empty test #12929

wants to merge 1 commit into from

Conversation

arturgvieira-zz
Copy link

@arturgvieira-zz arturgvieira-zz commented May 9, 2017

Replaced common.PORT in the following test.
test-dgram-send-callback-buffer-empty-address.js

Ref: #12376

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

test dgram

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label May 9, 2017
@mscdex mscdex added the dgram Issues and PRs related to the dgram subsystem / UDP. label May 9, 2017
@Trott
Copy link
Member

Trott commented May 10, 2017

Is the added complexity here better than just keeping the test simple and moving to sequential? I don't have an opinion either way, but I imagine others might. @nodejs/testing

Also: At least technically, I don't think this gets rid of the port collision issue that common.PORT has, although it does greatly narrow the window for collisions. Another Node.js test (running in parallel) could still open something on the port used here in the bit of time between this test closing and then sending. Since UDP is send-it-and-forget-it, that probably doesn't matter for this test, but it might matter for the other test that is listening. A reason to move to sequential instead? Or am I over-thinking things here? I'm fine either way, but again, I imagine others might have opinions. @nodejs/testing again

@Trott
Copy link
Member

Trott commented May 10, 2017

(Also: I would expect make jslint to flag an error here involving a missing newline at the end of the file.)

@arturgvieira-zz
Copy link
Author

arturgvieira-zz commented May 10, 2017

I appreciate the comments, either way, is fine with me also. I followed the algorithm from another test which is also on your list, commit d289678 , test-dgram-close-in-listening.js the same modification.

@arturgvieira-zz arturgvieira-zz changed the title test: remove common.PORT from test test: remove common.PORT in dgram cb address test May 10, 2017
@arturgvieira-zz arturgvieira-zz changed the title test: remove common.PORT in dgram cb address test test: replace port in dgram cb address empty test May 10, 2017
@arturgvieira-zz
Copy link
Author

@Trott Also corrected the missing newline at the end of the file. Nice catch.


portGetter.close();
}));

Copy link
Member

Choose a reason for hiding this comment

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

Nit: missing new line at the end of file.

@lpinca
Copy link
Member

lpinca commented May 10, 2017

I'm not sure either, as @Trott said this doesn't completely remove port collisions and makes the test harder to grok.
I would prefer to move these tests to sequential.

@lpinca
Copy link
Member

lpinca commented May 10, 2017

On second thought, the socket (client) has not been bound so it will pick a random port when calling send().

I think destination port doesn't matter so common.PORT is probably fine in this case and the original test doesn't need to be changed.

@arturgvieira-zz
Copy link
Author

arturgvieira-zz commented May 10, 2017

@lpinca Ok, I'll remove the changes and move the tests to sequential.

@arturgvieira-zz arturgvieira-zz changed the title test: replace port in dgram cb address empty test test: move to sequential dgram cd address empty test May 10, 2017
@arturgvieira-zz
Copy link
Author

@lpinca @Trott All done, tests moved to sequential.

@lpinca
Copy link
Member

lpinca commented May 11, 2017

As I wrote in my last comment I think the test can be left as is. There is no need to move it sequential.

client.send(buf, common.PORT, onMessage);

The code above bind the socket on a random port. common.PORT here is the destination port and it can be any port, it doesn't matter.

@arturgvieira-zz
Copy link
Author

I apologize, misunderstood your comment. I'll close the PR.

@arturgvieira-zz arturgvieira-zz deleted the commonPort03-branch branch May 11, 2017 05:50
@lpinca
Copy link
Member

lpinca commented May 11, 2017

No problem. Also wait for other collaborators feedback, maybe I am missing something :)

@arturgvieira-zz arturgvieira-zz restored the commonPort03-branch branch May 11, 2017 05:54
@arturgvieira-zz
Copy link
Author

Sorry, I am super new. I'll reopen the PR.

@cjihrig
Copy link
Contributor

cjihrig commented May 11, 2017

It is possible for these dgram tests to bind to the port to prevent port collisions. The socket would end up sending to itself and just ignore the data. It adds pretty minimal complexity, and allows the tests to stay in parallel.

@lpinca
Copy link
Member

lpinca commented May 11, 2017

@arturgvieira, @cjihrig is suggesting something like this

diff --git a/test/parallel/test-dgram-send-callback-buffer-empty-address.js b/test/parallel/test-dgram-send-callback-buffer-empty-address.js
index 67e64d6bfe..5b3b1c41a1 100644
--- a/test/parallel/test-dgram-send-callback-buffer-empty-address.js
+++ b/test/parallel/test-dgram-send-callback-buffer-empty-address.js
@@ -14,4 +14,4 @@ const onMessage = common.mustCall(function(err, bytes) {
   client.close();
 });
 
-client.send(buf, common.PORT, onMessage);
+client.bind(0, () => client.send(buf, client.address().port, onMessage));

@arturgvieira-zz
Copy link
Author

arturgvieira-zz commented May 11, 2017

@lpinga Understood and it seems like a good way to go, I will go ahead and update the PRs making that change.

Replaced common.PORT in the following test.
test-dgram-send-callback-buffer-empty-address.js

Ref: #12376
@arturgvieira-zz arturgvieira-zz changed the title test: move to sequential dgram cd address empty test test: replace port in dgram cd address empty test May 11, 2017
@arturgvieira-zz
Copy link
Author

@lpinca All done, updated the PRs with the change requested.

@@ -14,4 +14,4 @@ const onMessage = common.mustCall(function(err, bytes) {
client.close();
});

client.send(buf, common.PORT, onMessage);
client.bind(0, () => client.send(buf, client.address().port, onMessage));
Copy link
Member

Choose a reason for hiding this comment

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

Probably a good idea to wrap the callback in common.mustCall().

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a bad idea. onMessage() is wrapped in a mustCall(), so in this case not strictly necessary. No strong preference.

Copy link
Member

@Trott Trott May 11, 2017

Choose a reason for hiding this comment

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

Ah, yeah, if onMessage is already wrapped then the additional wrapping suggested by me above is actually not needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I also find common.mustCall() a bit redundant here which is the reason why I didn't suggest it in the first place.

@lpinca
Copy link
Member

lpinca commented May 12, 2017

@lpinca
Copy link
Member

lpinca commented May 22, 2017

Landed in 4c84734.

@lpinca lpinca closed this May 22, 2017
lpinca pushed a commit that referenced this pull request May 22, 2017
Replace common.PORT with available port assigned by the operating
system in test-dgram-send-callback-buffer-empty-address.

PR-URL: #12929
Refs: #12376
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
jasnell pushed a commit that referenced this pull request May 23, 2017
Replace common.PORT with available port assigned by the operating
system in test-dgram-send-callback-buffer-empty-address.

PR-URL: #12929
Refs: #12376
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
jasnell pushed a commit that referenced this pull request May 23, 2017
Replace common.PORT with available port assigned by the operating
system in test-dgram-send-callback-buffer-empty-address.

PR-URL: #12929
Refs: #12376
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@jasnell jasnell mentioned this pull request May 28, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dgram Issues and PRs related to the dgram subsystem / UDP. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants