-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
Conversation
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.
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); |
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.
Instead of 127.0.0.1
, couldn't you use server.address().address
?
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, but it looks like there are a few other improvements that could be made to this test (var
-> const
, common.mustCall()
, assert.strictEqual()
, etc.).
9829c3c
to
27ad46b
Compare
@cjihrig |
assert.equal(data.toString(), 'hello'); | ||
}); | ||
assert.strictEqual(data.toString(), 'hello'); | ||
})); |
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.
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.
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.
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(); |
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.
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) => { |
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 common.mustCall()
here too. Otherwise, there is no guarantee that the process.once('message', ...)
handler is added.
|
||
handle.on('end', function() { | ||
handle.on('end', () => { |
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.mustCall()
here as well.
27ad46b
to
d7f29a0
Compare
@cjihrig @santigimeno @jasnell |
CI is running again on https://ci.nodejs.org/job/node-test-pull-request/4909/ . |
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:
|
@akito0107 can you please take a look at the windows test failure? |
3927897
to
644967c
Compare
This commit improves test-cluster-net-send as below - change function to arrow function - ensure data event is emitted exactly once
644967c
to
fbd8c9f
Compare
@jasnell This error might be caused by using |
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, |
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 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
Ping... status update on this one? |
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. |
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
test, cluster
Description of change
This commit improves test-cluster-net-send as below;
This is a part of Code And Learn at NodeFest 2016 Challenge
nodejs/code-and-learn#58