Browse Source

test: fix flaky test-http-set-timeout-server

Make the servers listen on a free port number picked by the OS to avoid
rare `EADDRINUSE` errors on `SmartOS`.

Fixes: https://github.com/nodejs/node/issues/6197
PR-URL: https://github.com/nodejs/node/pull/6248
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6.x
Santiago Gimeno 9 years ago
committed by James M Snell
parent
commit
4dcb1a2654
  1. 55
      test/parallel/test-http-set-timeout-server.js

55
test/parallel/test-http-set-timeout-server.js

@ -30,7 +30,9 @@ test(function serverTimeout(cb) {
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
// just do nothing, we should get a timeout event. // 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) { var s = server.setTimeout(50, function(socket) {
caughtTimeout = true; caughtTimeout = true;
socket.destroy(); socket.destroy();
@ -38,7 +40,6 @@ test(function serverTimeout(cb) {
cb(); cb();
}); });
assert.ok(s instanceof http.Server); assert.ok(s instanceof http.Server);
http.get({ port: common.PORT }).on('error', function() {});
}); });
test(function serverRequestTimeout(cb) { test(function serverRequestTimeout(cb) {
@ -56,11 +57,13 @@ test(function serverRequestTimeout(cb) {
}); });
assert.ok(s instanceof http.IncomingMessage); assert.ok(s instanceof http.IncomingMessage);
}); });
server.listen(common.PORT); server.listen(common.mustCall(function() {
var req = http.request({ port: common.PORT, method: 'POST' }); var port = server.address().port;
req.on('error', function() {}); var req = http.request({ port: port, method: 'POST' });
req.write('Hello'); req.on('error', function() {});
// req is in progress req.write('Hello');
// req is in progress
}));
}); });
test(function serverResponseTimeout(cb) { test(function serverResponseTimeout(cb) {
@ -78,8 +81,10 @@ test(function serverResponseTimeout(cb) {
}); });
assert.ok(s instanceof http.OutgoingMessage); assert.ok(s instanceof http.OutgoingMessage);
}); });
server.listen(common.PORT); server.listen(common.mustCall(function() {
http.get({ port: common.PORT }).on('error', function() {}); var port = server.address().port;
http.get({ port: port }).on('error', function() {});
}));
}); });
test(function serverRequestNotTimeoutAfterEnd(cb) { test(function serverRequestNotTimeoutAfterEnd(cb) {
@ -104,8 +109,10 @@ test(function serverRequestNotTimeoutAfterEnd(cb) {
server.close(); server.close();
cb(); cb();
}); });
server.listen(common.PORT); server.listen(common.mustCall(function() {
http.get({ port: common.PORT }).on('error', function() {}); var port = server.address().port;
http.get({ port: port }).on('error', function() {});
}));
}); });
test(function serverResponseTimeoutWithPipeline(cb) { test(function serverResponseTimeoutWithPipeline(cb) {
@ -125,12 +132,14 @@ test(function serverResponseTimeoutWithPipeline(cb) {
server.close(); server.close();
cb(); cb();
}); });
server.listen(common.PORT); server.listen(common.mustCall(function() {
var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() { var port = server.address().port;
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); var c = net.connect({ port: port, allowHalfOpen: true }, function() {
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /3 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) { test(function idleTimeout(cb) {
@ -158,9 +167,11 @@ test(function idleTimeout(cb) {
cb(); cb();
}); });
assert.ok(s instanceof http.Server); assert.ok(s instanceof http.Server);
server.listen(common.PORT); server.listen(common.mustCall(function() {
var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() { var port = server.address().port;
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); var c = net.connect({ port: port, allowHalfOpen: true }, function() {
// Keep-Alive c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
}); // Keep-Alive
});
}));
}); });

Loading…
Cancel
Save