From 94e1da9af6e036f1db863f86cc8c038abe77b012 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Fri, 15 Apr 2016 09:04:00 +0000 Subject: [PATCH] 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 Reviewed-By: James M Snell --- test/parallel/test-http-set-timeout-server.js | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/test/parallel/test-http-set-timeout-server.js b/test/parallel/test-http-set-timeout-server.js index 67db16d2a26111..d530503aa1e9aa 100644 --- a/test/parallel/test-http-set-timeout-server.js +++ b/test/parallel/test-http-set-timeout-server.js @@ -30,7 +30,9 @@ 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(); @@ -38,7 +40,6 @@ test(function serverTimeout(cb) { cb(); }); assert.ok(s instanceof http.Server); - http.get({ port: common.PORT }).on('error', function() {}); }); test(function serverRequestTimeout(cb) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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 + }); + })); });