Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d615757

Browse filesBrowse files
cjihrigMyles Borins
authored andcommitted
test: fix flaky test-net-socket-local-address
Prior to this commit, the test was flaky because it was executing the majority of its logic in a function called from the client and multiple events on the server. This commit simplifies the test by separating the server's connection and listening events, and isolating the client logic. Refs: #4476 Refs: #4644 PR-URL: #4650 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 40c8e6d commit d615757
Copy full SHA for d615757

File tree

Expand file treeCollapse file tree

1 file changed

+13
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-19
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-net-socket-local-address.js
+13-19Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,29 @@ if (common.inFreeBSDJail) {
1212
var conns = 0;
1313
var clientLocalPorts = [];
1414
var serverRemotePorts = [];
15-
16-
const server = net.createServer(function(socket) {
15+
const client = new net.Socket();
16+
const server = net.createServer(socket => {
1717
serverRemotePorts.push(socket.remotePort);
18-
testConnect();
18+
socket.end();
1919
});
2020

21-
const client = new net.Socket();
22-
23-
server.on('close', common.mustCall(function() {
21+
server.on('close', common.mustCall(() => {
2422
assert.deepEqual(clientLocalPorts, serverRemotePorts,
2523
'client and server should agree on the ports used');
26-
assert.equal(2, conns);
24+
assert.strictEqual(2, conns);
2725
}));
2826

29-
server.listen(common.PORT, common.localhostIPv4, testConnect);
27+
server.listen(common.PORT, common.localhostIPv4, connect);
3028

31-
function testConnect() {
32-
if (conns > serverRemotePorts.length || conns > clientLocalPorts.length) {
33-
// We're waiting for a callback to fire.
29+
function connect() {
30+
if (conns === 2) {
31+
server.close();
3432
return;
3533
}
3634

37-
if (conns === 2) {
38-
return server.close();
39-
}
40-
client.connect(common.PORT, common.localhostIPv4, function() {
41-
clientLocalPorts.push(this.localPort);
42-
this.once('close', testConnect);
43-
this.destroy();
44-
});
4535
conns++;
36+
client.once('close', connect);
37+
client.connect(common.PORT, common.localhostIPv4, () => {
38+
clientLocalPorts.push(client.localPort);
39+
});
4640
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.