Skip to content

Commit 4b43bf0

Browse files
Trottrvagg
authored andcommitted
test: fix flaky test-net-socket-local-address
test-net-socket-local-address had a race condition that resulted in unreliability on FreeBSD and Windows. This changes fixes the issue. Fixes: #2475 PR-URL: #4109 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Johan Bergström <[email protected]>
1 parent f3417e2 commit 4b43bf0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

test/parallel/parallel.status

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ test-child-process-exit-code : PASS,FLAKY
2121
[$system==solaris] # Also applies to SmartOS
2222

2323
[$system==freebsd]
24-
test-net-socket-local-address : PASS,FLAKY

test/parallel/test-net-socket-local-address.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var serverRemotePorts = [];
1515

1616
const server = net.createServer(function(socket) {
1717
serverRemotePorts.push(socket.remotePort);
18-
conns++;
18+
testConnect();
1919
});
2020

2121
const client = new net.Socket();
@@ -29,12 +29,18 @@ server.on('close', common.mustCall(function() {
2929
server.listen(common.PORT, common.localhostIPv4, testConnect);
3030

3131
function testConnect() {
32-
if (conns == 2) {
32+
if (conns > serverRemotePorts.length || conns > clientLocalPorts.length) {
33+
// We're waiting for a callback to fire.
34+
return;
35+
}
36+
37+
if (conns === 2) {
3338
return server.close();
3439
}
3540
client.connect(common.PORT, common.localhostIPv4, function() {
3641
clientLocalPorts.push(this.localPort);
3742
this.once('close', testConnect);
3843
this.destroy();
3944
});
45+
conns++;
4046
}

0 commit comments

Comments
 (0)