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-http-set-timeout-server #6248

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
55 changes: 33 additions & 22 deletions test/parallel/test-http-set-timeout-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ test(function serverTimeout(cb) {
var server = http.createServer(function(req, res) {
// just do nothing, we should get a timeout event.
});
server.listen(common.PORT);
server.listen(common.mustCall(function() {
http.get({ port: server.address().port }).on('error', function() {});
}));
var s = server.setTimeout(50, function(socket) {
caughtTimeout = true;
socket.destroy();
server.close();
cb();
});
assert.ok(s instanceof http.Server);
http.get({ port: common.PORT }).on('error', function() {});
});

test(function serverRequestTimeout(cb) {
Expand All @@ -56,11 +57,13 @@ test(function serverRequestTimeout(cb) {
});
assert.ok(s instanceof http.IncomingMessage);
});
server.listen(common.PORT);
var req = http.request({ port: common.PORT, method: 'POST' });
req.on('error', function() {});
req.write('Hello');
// req is in progress
server.listen(common.mustCall(function() {
var port = server.address().port;
var req = http.request({ port: port, method: 'POST' });
req.on('error', function() {});
req.write('Hello');
// req is in progress
}));
});

test(function serverResponseTimeout(cb) {
Expand All @@ -78,8 +81,10 @@ test(function serverResponseTimeout(cb) {
});
assert.ok(s instanceof http.OutgoingMessage);
});
server.listen(common.PORT);
http.get({ port: common.PORT }).on('error', function() {});
server.listen(common.mustCall(function() {
var port = server.address().port;
http.get({ port: port }).on('error', function() {});
}));
});

test(function serverRequestNotTimeoutAfterEnd(cb) {
Expand All @@ -104,8 +109,10 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
server.close();
cb();
});
server.listen(common.PORT);
http.get({ port: common.PORT }).on('error', function() {});
server.listen(common.mustCall(function() {
var port = server.address().port;
http.get({ port: port }).on('error', function() {});
}));
});

test(function serverResponseTimeoutWithPipeline(cb) {
Expand All @@ -125,12 +132,14 @@ test(function serverResponseTimeoutWithPipeline(cb) {
server.close();
cb();
});
server.listen(common.PORT);
var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() {
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
});
server.listen(common.mustCall(function() {
var port = server.address().port;
var c = net.connect({ port: port, allowHalfOpen: true }, function() {
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
});
}));
});

test(function idleTimeout(cb) {
Expand Down Expand Up @@ -158,9 +167,11 @@ test(function idleTimeout(cb) {
cb();
});
assert.ok(s instanceof http.Server);
server.listen(common.PORT);
var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() {
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
// Keep-Alive
});
server.listen(common.mustCall(function() {
var port = server.address().port;
var c = net.connect({ port: port, allowHalfOpen: true }, function() {
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
// Keep-Alive
});
}));
});