Skip to content
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: fix flaky test-net-server-max-connections test on SmartOS #3830

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions test/parallel/test-net-server-max-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ function makeConnection(index) {
if (index + 1 < N) {
makeConnection(index + 1);
}

c.on('close', function() {
console.error('closed %d', index);
closes++;

if (closes < N / 2) {
assert.ok(server.maxConnections <= index,
index +
' was one of the first closed connections ' +
'but shouldnt have been');
}

if (closes === N / 2) {
var cb;
console.error('calling wait callback.');
while (cb = waits.shift()) {
cb();
}
server.close();
}

if (index < server.maxConnections) {
assert.equal(true, gotData,
index + ' didn\'t get data, but should have');
} else {
assert.equal(false, gotData,
index + ' got data, but shouldn\'t have');
}
});
});

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

c.on('error', function(e) {
console.error('error %d: %s', index, e);
});

c.on('close', function() {
console.error('closed %d', index);
closes++;

if (closes < N / 2) {
assert.ok(server.maxConnections <= index,
index +
' was one of the first closed connections ' +
'but shouldnt have been');
}

if (closes === N / 2) {
var cb;
console.error('calling wait callback.');
while (cb = waits.shift()) {
cb();
}
server.close();
}

if (index < server.maxConnections) {
assert.equal(true, gotData,
index + ' didn\'t get data, but should have');
} else {
assert.equal(false, gotData,
index + ' got data, but shouldn\'t have');
// Retry if SmartOS and ECONNREFUSED. See
// https://github.com/nodejs/node/issues/2663.
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
c.connect(common.PORT);
}
console.error('error %d: %s', index, e);
});
}

Expand Down