Skip to content

Commit 93b3a37

Browse files
Trottrvagg
authored andcommitted
test: fix flaky SmartOS test
SmartOS has an issue where it will trigger ECONNREFUSED when it should not. See https://smartos.org/bugview/OS-2767. This change adds logic to test-net-server-max-connections.js to work around the issue. Fixes: #2663 PR-URL: #3830 Reviewed-By: James M Snell <[email protected]>
1 parent 44177f0 commit 93b3a37

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

test/parallel/test-net-server-max-connections.js

+34-29
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ function makeConnection(index) {
3636
if (index + 1 < N) {
3737
makeConnection(index + 1);
3838
}
39+
40+
c.on('close', function() {
41+
console.error('closed %d', index);
42+
closes++;
43+
44+
if (closes < N / 2) {
45+
assert.ok(server.maxConnections <= index,
46+
index +
47+
' was one of the first closed connections ' +
48+
'but shouldnt have been');
49+
}
50+
51+
if (closes === N / 2) {
52+
var cb;
53+
console.error('calling wait callback.');
54+
while (cb = waits.shift()) {
55+
cb();
56+
}
57+
server.close();
58+
}
59+
60+
if (index < server.maxConnections) {
61+
assert.equal(true, gotData,
62+
index + ' didn\'t get data, but should have');
63+
} else {
64+
assert.equal(false, gotData,
65+
index + ' got data, but shouldn\'t have');
66+
}
67+
});
3968
});
4069

4170
c.on('end', function() { c.end(); });
@@ -46,36 +75,12 @@ function makeConnection(index) {
4675
});
4776

4877
c.on('error', function(e) {
49-
console.error('error %d: %s', index, e);
50-
});
51-
52-
c.on('close', function() {
53-
console.error('closed %d', index);
54-
closes++;
55-
56-
if (closes < N / 2) {
57-
assert.ok(server.maxConnections <= index,
58-
index +
59-
' was one of the first closed connections ' +
60-
'but shouldnt have been');
61-
}
62-
63-
if (closes === N / 2) {
64-
var cb;
65-
console.error('calling wait callback.');
66-
while (cb = waits.shift()) {
67-
cb();
68-
}
69-
server.close();
70-
}
71-
72-
if (index < server.maxConnections) {
73-
assert.equal(true, gotData,
74-
index + ' didn\'t get data, but should have');
75-
} else {
76-
assert.equal(false, gotData,
77-
index + ' got data, but shouldn\'t have');
78+
// Retry if SmartOS and ECONNREFUSED. See
79+
// https://github.com/nodejs/node/issues/2663.
80+
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
81+
c.connect(common.PORT);
7882
}
83+
console.error('error %d: %s', index, e);
7984
});
8085
}
8186

0 commit comments

Comments
 (0)