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-net-server-address.js #8586

Closed

Conversation

akito0107
Copy link
Contributor

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

test

Description of change

Refactored test as a below;

  • 'var' to 'const'
  • function to arrow function

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Sep 17, 2016
@mscdex mscdex added the net Issues and PRs related to the net subsystem. label Sep 17, 2016
@yosuke-furukawa
Copy link
Member

LGTM

@cjihrig
Copy link
Contributor

cjihrig commented Sep 17, 2016

Generally, LGTM, but we might be able to improve this further using common.mustCall() and common.fail() in a few places.

@akito0107
Copy link
Contributor Author

@cjihrig Thank you for your advice, I fixed!

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

LGTM with a suggestion

server_ipv4.on('error', function(e) {
console.log('Error on ipv4 socket: ' + e.toString());
});
server_ipv4.on('error', common.fail);
Copy link
Member

Choose a reason for hiding this comment

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

maybe assert.ifError instead ?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Using assert.ifError will print a bit more information than common.fail.

server_ipv6.on('error', function(e) {
console.log('Error on ipv6 socket: ' + e.toString());
});
server_ipv6.on('error', common.fail);
Copy link
Member

@targos targos Sep 17, 2016

Choose a reason for hiding this comment

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

ditto and others below

console.log('Error on ipv4 socket: ' + e.toString());
});

server_ipv4.listen(common.PORT, common.localhostIPv4, function() {
var address_ipv4 = server_ipv4.address();
server_ipv4.listen(common.PORT, common.localhostIPv4, () => {
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 a common.mustCall() here?


server_ipv6.on('error', function(e) {
server_ipv6.on('error', (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you aren't the original author of this test, but is it expected that this will never be called? If so, this callback could be replaced with common.fail.

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 if the CI is happy.

@cjihrig
Copy link
Contributor

cjihrig commented Sep 17, 2016

Copy link
Member

@imyller imyller left a comment

Choose a reason for hiding this comment

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

LGTM

@imyller
Copy link
Member

imyller commented Sep 19, 2016

@imyller
Copy link
Member

imyller commented Sep 19, 2016

If CI is green, I'll start the process of landing this.

@imyller imyller self-assigned this Sep 19, 2016
@imyller
Copy link
Member

imyller commented Sep 19, 2016

We might have a problem here.

CI failed on multiple platforms with this refactored test:

not ok 1226 sequential/test-net-server-address
# 
# assert.js:85
#   throw new assert.AssertionError({
#   ^
# AssertionError: Error: listen EADDRINUSE 127.0.0.1:12346
#     at Server.exports.fail (/home/iojs/build/workspace/node-test-commit-linux-fips/nodes/ubuntu1404-64/test/common.js:438:10)
#     at emitOne (events.js:96:13)
#     at Server.emit (events.js:188:7)
#     at emitErrorNT (net.js:1274:8)
#     at _combinedTickCallback (internal/process/next_tick.js:74:11)
#     at process._tickCallback (internal/process/next_tick.js:98:9)
#     at Module.runMain (module.js:596:11)
#     at run (bootstrap_node.js:382:7)
#     at startup (bootstrap_node.js:137:9)
#     at bootstrap_node.js:497:3
  ---
  duration_ms: 0.113

-1 for landing this until CI failure is resolved.

/cc @akito0107

@imyller
Copy link
Member

imyller commented Sep 20, 2016

@santigimeno
Copy link
Member

I think the problem is that the test should have been failing before this change, but was not asserting on errors, just printing on console.error, so it did not. Solutions could be: increasing common.PORT on every call to server listen or wait for the current server to be closed before start listening on the next.

@imyller
Copy link
Member

imyller commented Sep 20, 2016

I think you're absolute right @santigimeno, Thank you.

btw @addaleax Nice to see that code+learn session cleanups have now resulted us in finding an pre-existing unnoticed test issue.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Generally LGTM. If the assert.ifError was used I'd be even happier tho ;-)


server_ipv4.listen(common.PORT, common.localhostIPv4, function() {
var address_ipv4 = server_ipv4.address();
server_ipv4.listen(common.PORT, common.localhostIPv4, common.mustCall(() => {
Copy link
Member

Choose a reason for hiding this comment

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

common.PORT+1

server_ipv4.listen(common.PORT, common.localhostIPv4, function() {
var address_ipv4 = server_ipv4.address();
server_ipv4.listen(common.PORT, common.localhostIPv4, common.mustCall(() => {
const address_ipv4 = server_ipv4.address();
assert.strictEqual(address_ipv4.address, common.localhostIPv4);
assert.strictEqual(address_ipv4.port, common.PORT);
Copy link
Member

@imyller imyller Sep 20, 2016

Choose a reason for hiding this comment

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

common.PORT+1


server_ipv6.listen(common.PORT, localhost_ipv6, function() {
var address_ipv6 = server_ipv6.address();
server_ipv6.listen(common.PORT, localhost_ipv6, common.mustCall(() => {
Copy link
Member

Choose a reason for hiding this comment

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

common.PORT+2

server_ipv6.listen(common.PORT, localhost_ipv6, function() {
var address_ipv6 = server_ipv6.address();
server_ipv6.listen(common.PORT, localhost_ipv6, common.mustCall(() => {
const address_ipv6 = server_ipv6.address();
assert.strictEqual(address_ipv6.address, localhost_ipv6);
assert.strictEqual(address_ipv6.port, common.PORT);
Copy link
Member

Choose a reason for hiding this comment

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

common.PORT+2


// Specify the port number
server1.listen(common.PORT, function() {
var address = server1.address();
server1.listen(common.PORT, common.mustCall(() => {
Copy link
Member

Choose a reason for hiding this comment

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

common.PORT+3

server1.listen(common.PORT, function() {
var address = server1.address();
server1.listen(common.PORT, common.mustCall(() => {
const address = server1.address();
assert.strictEqual(address.address, anycast_ipv6);
assert.strictEqual(address.port, common.PORT);
Copy link
Member

Choose a reason for hiding this comment

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

common.PORT+3

@imyller
Copy link
Member

imyller commented Sep 20, 2016

@akito0107

To fix issue with multiple servers listening on same port (EADDRINUSE), could you please upgrade each common.PORT reference so that each server gets a separate port.

I've pointed out the lines in my previous code comments.

You can do common.PORT + <n> or alternatively common.PORT++ for each server.listen() call.

@imyller
Copy link
Member

imyller commented Sep 25, 2016

/ping @akito0107

@imyller imyller added the wip Issues and PRs that are still a work in progress. label Sep 27, 2016
@imyller imyller removed the wip Issues and PRs that are still a work in progress. label Sep 27, 2016
@yosuke-furukawa
Copy link
Member

According to this PR, #8694
we would be better to use listen(0) instead of common.PORT.

@imyller
Copy link
Member

imyller commented Sep 28, 2016

@yosuke-furukawa

Generally I'd agree, but this PR is already referenced for this in #8694. Specific purpose here is to test with fixed port numbers instead of automatic port assignment.

#8694 (comment)

@yosuke-furukawa
Copy link
Member

@imyller
oops, I didn't see the test detail. Thank you. @akito0107 please ignore my comment.

Refactored test as a below
- 'var' to 'const'
- functon to arrow function
- using common.mustCall() and common.fail()
@akito0107
Copy link
Contributor Author

@imyller
Sorry for late reply...

I fixed it!

@imyller
Copy link
Member

imyller commented Sep 28, 2016

Thank you, @akito0107 !

Let's see how this works.

New CI: https://ci.nodejs.org/job/node-test-pull-request/4315/

@imyller
Copy link
Member

imyller commented Sep 28, 2016

CI run is ok. Failures are known/unrelated issues.

@imyller
Copy link
Member

imyller commented Sep 29, 2016

I'll start landing this:

  • Five LGTMs
  • No objections
  • CI tests passed (only known/unrelated failures)

@imyller
Copy link
Member

imyller commented Sep 29, 2016

Landed in 506cda6

Thank you for your effort and contribution, @akito0107 👍

@imyller imyller closed this Sep 29, 2016
@imyller imyller removed their assignment Sep 29, 2016
imyller pushed a commit that referenced this pull request Sep 29, 2016
Refactored test:
- 'var' to 'const'
- functon to arrow function
- using common.mustCall() and common.fail()

PR-URL: #8586
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit that referenced this pull request Sep 29, 2016
Refactored test:
- 'var' to 'const'
- functon to arrow function
- using common.mustCall() and common.fail()

PR-URL: #8586
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Fishrock123 pushed a commit that referenced this pull request Oct 11, 2016
Refactored test:
- 'var' to 'const'
- functon to arrow function
- using common.mustCall() and common.fail()

PR-URL: #8586
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants