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: improve test-cluster-net-send.js #9570

Closed

Conversation

akito0107
Copy link
Contributor

@akito0107 akito0107 commented Nov 12, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test, cluster

Description of change

This commit improves test-cluster-net-send as below;

  • use port 0 instead of common.PORT
  • use common.mustCall
  • use assert.strictEqual instead of assert.equal
  • change var to const or let (if possible)
  • change function to arrow function

This is a part of Code And Learn at NodeFest 2016 Challenge
nodejs/code-and-learn#58

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Nov 12, 2016
@mscdex mscdex added cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem. labels Nov 12, 2016
Copy link
Contributor

@shigeki shigeki left a comment

Choose a reason for hiding this comment

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

CI submitted by @mscdex was running on https://ci.nodejs.org/job/node-test-pull-request/4828/ . Two tests were failed, one is due to missing g++ in CentOS7-64 build env and others Jenkins error on armv8. Others are fine. LGTM.

server.listen(common.PORT, function() {
socket = net.connect(common.PORT, '127.0.0.1', socketConnected);
server.listen(0, function() {
socket = net.connect(server.address().port, '127.0.0.1', socketConnected);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of 127.0.0.1, couldn't you use server.address().address?

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

LGTM, but it looks like there are a few other improvements that could be made to this test (var -> const, common.mustCall(), assert.strictEqual(), etc.).

@akito0107 akito0107 force-pushed the improve-test-cluster-net-send branch 2 times, most recently from 9829c3c to 27ad46b Compare November 14, 2016 11:46
@akito0107
Copy link
Contributor Author

@cjihrig
Thank you for your advice ! I fixed it !

assert.equal(data.toString(), 'hello');
});
assert.strictEqual(data.toString(), 'hello');
}));
Copy link
Member

Choose a reason for hiding this comment

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

Now that you have added the common.mustCall wrapper I think you can remove the called variable.
Also, though highly unlikely, the data listener could be called more than once, so I would check for the data validity in the end listener.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, drop the called variable and the process.once('exit', ...), move the common.mustCall() from the data handler to the end handler, and do a concatenation in the data handler.

});

process.on('disconnect', function() {
process.on('disconnect', () => {
process.exit();
server.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this unreachable code?

It would be better to have the process exit naturally, rather than call process.exit().

var server = net.createServer(function(c) {
process.once('message', function(msg) {
assert.equal(msg, 'got');
const server = net.createServer((c) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add common.mustCall() here too. Otherwise, there is no guarantee that the process.once('message', ...) handler is added.


handle.on('end', function() {
handle.on('end', () => {
Copy link
Member

Choose a reason for hiding this comment

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

common.mustCall() here as well.

@akito0107
Copy link
Contributor Author

@cjihrig @santigimeno @jasnell
Thank you all! I fixed it.

@shigeki
Copy link
Contributor

shigeki commented Nov 19, 2016

CI is running again on https://ci.nodejs.org/job/node-test-pull-request/4909/ .

@targos
Copy link
Member

targos commented Nov 27, 2016

@targos
Copy link
Member

targos commented Nov 27, 2016

The test fails on Windows: https://ci.nodejs.org/job/node-test-binary-windows/4954/RUN_SUBSET=3,VS_VERSION=vs2015,label=win2008r2/tapTestReport/

Example output on my PC:

[15828] master
[15660] worker
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: connect EADDRNOTAVAIL :::62283
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)

@jasnell
Copy link
Member

jasnell commented Jan 11, 2017

@akito0107 can you please take a look at the windows test failure?

@akito0107 akito0107 force-pushed the improve-test-cluster-net-send branch 2 times, most recently from 3927897 to 644967c Compare February 3, 2017 04:55
This commit improves test-cluster-net-send as below
- change function to arrow function
- ensure data event is emitted exactly once
@akito0107 akito0107 force-pushed the improve-test-cluster-net-send branch from 644967c to fbd8c9f Compare February 3, 2017 05:00
@akito0107
Copy link
Contributor Author

akito0107 commented Feb 3, 2017

@jasnell
Sorry for late.

This error might be caused by using sever.listen(0), so, I restored sever.listen(0) to server.listen(common.PORT).
I would like to check Windows CI test is passed.

server.listen(common.PORT, function() {
socket = net.connect(common.PORT, '127.0.0.1', socketConnected);
server.listen(common.PORT, () => {
socket = net.connect(server.address().port, server.address().address,
Copy link
Member

@gibfahn gibfahn Feb 3, 2017

Choose a reason for hiding this comment

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

I think this is the same issue as the one I saw in #10854

If so, the problem is that you can't use server.address().address here. You should be listening on 0 (i.e. all IPv6 and IPv4 addresses), in which case server.address().address resolves to ::. On linux this sometimes resolves to 127.0.0.1 if there is no IPv6 support on the machine, but this isn't the case on all platforms.

Changing to:

-  server.listen(common.PORT, () => {
-    socket = net.connect(server.address().port, server.address().address,
+  server.listen(0, () => {
+    socket = net.connect(server.address().port, 'localhost',

should fix the issue on all platforms. localhost should always resolve to either 127.0.0.1 or :: (either of which is fine).

cc/ @cjihrig

@jasnell
Copy link
Member

jasnell commented Mar 24, 2017

Ping... status update on this one?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 24, 2017
@fhinkel
Copy link
Member

fhinkel commented May 26, 2017

There hasn't been any activity here. I'm closing this. Feel free to reopen (or ping a collaborator) if I closed this in error.

@fhinkel fhinkel closed this May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem. stalled Issues and PRs that are stalled. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants