-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Conversation
LGTM |
Generally, LGTM, but we might be able to improve this further using |
d30af72
to
6a9052d
Compare
@cjihrig Thank you for your advice, I fixed! |
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 with a suggestion
server_ipv4.on('error', function(e) { | ||
console.log('Error on ipv4 socket: ' + e.toString()); | ||
}); | ||
server_ipv4.on('error', common.fail); |
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.
maybe assert.ifError
instead ?
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.
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); |
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.
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, () => { |
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.
Can you add a common.mustCall()
here?
|
||
server_ipv6.on('error', function(e) { | ||
server_ipv6.on('error', (e) => { |
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 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
.
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 if the CI is happy.
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
If CI is green, I'll start the process of landing this. |
We might have a problem here. CI failed on multiple platforms with this refactored test:
-1 for landing this until CI failure is resolved. /cc @akito0107 |
I think the problem is that the test should have been failing before this change, but was not asserting on errors, just printing on |
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. |
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.
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(() => { |
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.
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); |
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.
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(() => { |
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.
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); |
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.
common.PORT+2
|
||
// Specify the port number | ||
server1.listen(common.PORT, function() { | ||
var address = server1.address(); | ||
server1.listen(common.PORT, common.mustCall(() => { |
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.
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); |
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.
common.PORT+3
To fix issue with multiple servers listening on same port ( I've pointed out the lines in my previous code comments. You can do |
/ping @akito0107 |
According to this PR, #8694 |
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. |
@imyller |
Refactored test as a below - 'var' to 'const' - functon to arrow function - using common.mustCall() and common.fail()
6a9052d
to
7550376
Compare
@imyller I fixed it! |
Thank you, @akito0107 ! Let's see how this works. New CI: https://ci.nodejs.org/job/node-test-pull-request/4315/ |
CI run is ok. Failures are known/unrelated issues. |
I'll start landing this:
|
Landed in 506cda6 Thank you for your effort and contribution, @akito0107 👍 |
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>
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>
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>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
test
Description of change
Refactored test as a below;