Skip to content

Commit 840e533

Browse files
committed
test: fix parallel/test-net-socket-local-address
Fix flakiness where the client sometimes closed the server before the server had the chance to process the outstanding client connection. Make the server close itself instead. Fixes: #2475
1 parent e5d97fd commit 840e533

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

test/parallel/parallel.status

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@ var serverRemotePorts = [];
1515

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

2121
const client = new net.Socket();
2222

23-
server.on('close', common.mustCall(function() {
23+
process.on('exit', function() {
2424
assert.deepEqual(clientLocalPorts, serverRemotePorts,
2525
'client and server should agree on the ports used');
2626
assert.equal(2, conns);
27-
}));
27+
});
2828

2929
server.listen(common.PORT, common.localhostIPv4, testConnect);
3030

3131
function testConnect() {
32-
if (conns == 2) {
33-
return server.close();
34-
}
32+
if (conns >= 2) return;
3533
client.connect(common.PORT, common.localhostIPv4, function() {
3634
clientLocalPorts.push(this.localPort);
3735
this.once('close', testConnect);

0 commit comments

Comments
 (0)