Browse Source

test: use random ports where possible

This helps to prevent issues where a failed test can keep a bound
socket open long enough to cause other tests to fail with EADDRINUSE
because the same port number is used.

PR-URL: https://github.com/nodejs/node/pull/7045
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
v7.x
Brian White 9 years ago
parent
commit
2bc7841d0f
No known key found for this signature in database GPG Key ID: 606D7358F94DA209
  1. 13
      test/parallel/test-async-wrap-check-providers.js
  2. 6
      test/parallel/test-async-wrap-disabled-propagate-parent.js
  3. 6
      test/parallel/test-async-wrap-propagate-parent.js
  4. 4
      test/parallel/test-beforeexit-event.js
  5. 10
      test/parallel/test-child-process-disconnect.js
  6. 4
      test/parallel/test-child-process-fork-dgram.js
  7. 2
      test/parallel/test-child-process-fork-net.js
  8. 4
      test/parallel/test-child-process-fork-net2.js
  9. 4
      test/parallel/test-child-process-fork-regr-gh-2847.js
  10. 2
      test/parallel/test-child-process-recv-handle.js
  11. 4
      test/parallel/test-child-process-send-keep-open.js
  12. 2
      test/parallel/test-child-process-send-returns-boolean.js
  13. 4
      test/parallel/test-crypto-verify-failure.js
  14. 12
      test/parallel/test-dgram-address.js
  15. 12
      test/parallel/test-dgram-bind-default-address.js
  16. 39
      test/parallel/test-dgram-empty-packet.js
  17. 12
      test/parallel/test-dgram-error-message-address.js
  18. 9
      test/parallel/test-dgram-implicit-bind.js
  19. 4
      test/parallel/test-dgram-multicast-setTTL.js
  20. 5
      test/parallel/test-dgram-send-callback-multi-buffer.js
  21. 8
      test/parallel/test-dgram-send-callback-recursive.js
  22. 11
      test/parallel/test-dgram-send-default-host.js
  23. 4
      test/parallel/test-dgram-send-empty-array.js
  24. 22
      test/parallel/test-dgram-send-empty-buffer.js
  25. 4
      test/parallel/test-dgram-send-multi-buffer-copy.js
  26. 4
      test/parallel/test-dgram-setBroadcast.js
  27. 4
      test/parallel/test-dgram-setTTL.js
  28. 9
      test/parallel/test-dgram-udp4.js
  29. 11
      test/parallel/test-dgram-udp6-send-default-host.js
  30. 4
      test/parallel/test-domain-abort-on-uncaught.js
  31. 9
      test/parallel/test-domain-http-server.js
  32. 32
      test/parallel/test-domain-multi.js
  33. 2
      test/parallel/test-handle-wrap-isrefed.js
  34. 12
      test/parallel/test-http-1.0-keep-alive.js
  35. 7
      test/parallel/test-http-1.0.js
  36. 10
      test/parallel/test-http-abort-before-end.js
  37. 7
      test/parallel/test-http-abort-client.js
  38. 4
      test/parallel/test-http-abort-queued.js
  39. 8
      test/parallel/test-http-after-connect.js
  40. 138
      test/parallel/test-http-agent-destroyed-socket.js
  41. 52
      test/parallel/test-http-agent-error-on-idle.js
  42. 9
      test/parallel/test-http-agent-keepalive.js
  43. 6
      test/parallel/test-http-agent-maxsockets-regress-4050.js
  44. 6
      test/parallel/test-http-agent-maxsockets.js
  45. 6
      test/parallel/test-http-agent-no-protocol.js
  46. 4
      test/parallel/test-http-agent-null.js
  47. 7
      test/parallel/test-http-agent.js
  48. 6
      test/parallel/test-http-allow-req-after-204-res.js
  49. 8
      test/parallel/test-http-automatic-headers.js
  50. 19
      test/parallel/test-http-bind-twice.js
  51. 6
      test/parallel/test-http-blank-header.js
  52. 6
      test/parallel/test-http-buffer-sanity.js
  53. 6
      test/parallel/test-http-byteswritten.js
  54. 4
      test/parallel/test-http-catch-uncaughtexception.js
  55. 8
      test/parallel/test-http-chunk-problem.js
  56. 4
      test/parallel/test-http-chunked-304.js
  57. 6
      test/parallel/test-http-chunked.js
  58. 6
      test/parallel/test-http-client-abort-event.js
  59. 6
      test/parallel/test-http-client-abort.js
  60. 6
      test/parallel/test-http-client-abort2.js
  61. 9
      test/parallel/test-http-client-agent.js
  62. 6
      test/parallel/test-http-client-default-headers-exist.js
  63. 6
      test/parallel/test-http-client-encoding.js
  64. 6
      test/parallel/test-http-client-get-url.js
  65. 6
      test/parallel/test-http-client-parse-error.js
  66. 8
      test/parallel/test-http-client-race-2.js
  67. 8
      test/parallel/test-http-client-race.js
  68. 4
      test/parallel/test-http-client-reject-chunked-with-content-length.js
  69. 4
      test/parallel/test-http-client-reject-cr-no-lf.js
  70. 7
      test/parallel/test-http-client-timeout-agent.js
  71. 5
      test/parallel/test-http-client-timeout-event.js
  72. 5
      test/parallel/test-http-client-timeout-with-data.js
  73. 7
      test/parallel/test-http-client-timeout.js
  74. 6
      test/parallel/test-http-client-upload-buf.js
  75. 6
      test/parallel/test-http-client-upload.js
  76. 7
      test/parallel/test-http-conn-reset.js
  77. 6
      test/parallel/test-http-connect-req-res.js
  78. 8
      test/parallel/test-http-connect.js
  79. 10
      test/parallel/test-http-content-length.js
  80. 6
      test/parallel/test-http-contentLength0.js
  81. 10
      test/parallel/test-http-createConnection.js
  82. 6
      test/parallel/test-http-date-header.js
  83. 6
      test/parallel/test-http-default-encoding.js
  84. 18
      test/parallel/test-http-default-port.js
  85. 4
      test/parallel/test-http-destroyed-socket-write2.js
  86. 4
      test/parallel/test-http-double-content-length.js
  87. 4
      test/parallel/test-http-end-throw-socket-handling.js
  88. 6
      test/parallel/test-http-eof-on-connect.js
  89. 6
      test/parallel/test-http-exceptions.js
  90. 6
      test/parallel/test-http-expect-continue.js
  91. 4
      test/parallel/test-http-expect-handling.js
  92. 6
      test/parallel/test-http-extra-response.js
  93. 6
      test/parallel/test-http-flush-headers.js
  94. 4
      test/parallel/test-http-flush-response-headers.js
  95. 6
      test/parallel/test-http-flush.js
  96. 4
      test/parallel/test-http-full-response.js
  97. 4
      test/parallel/test-http-get-pipeline-problem.js
  98. 10
      test/parallel/test-http-head-request.js
  99. 6
      test/parallel/test-http-head-response-has-no-body-end.js
  100. 6
      test/parallel/test-http-head-response-has-no-body.js

13
test/parallel/test-async-wrap-check-providers.js

@ -81,12 +81,12 @@ net.createServer(function(c) {
net.createServer(function(c) {
c.end();
this.close(checkTLS);
}).listen(common.PORT, function() {
net.connect(common.PORT, noop);
}).listen(0, function() {
net.connect(this.address().port, noop);
});
dgram.createSocket('udp4').bind(common.PORT, function() {
this.send(Buffer.allocUnsafe(2), 0, 2, common.PORT, '::', () => {
dgram.createSocket('udp4').bind(0, function() {
this.send(Buffer.allocUnsafe(2), 0, 2, this.address().port, '::', () => {
this.close();
});
});
@ -100,8 +100,9 @@ function checkTLS() {
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
};
const server = tls.createServer(options, noop)
.listen(common.PORT, function() {
tls.connect(common.PORT, { rejectUnauthorized: false }, function() {
.listen(0, function() {
const connectOpts = { rejectUnauthorized: false };
tls.connect(this.address().port, connectOpts, function() {
this.destroy();
server.close();
});

6
test/parallel/test-async-wrap-disabled-propagate-parent.js

@ -1,6 +1,6 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const net = require('net');
const async_wrap = process.binding('async_wrap');
@ -40,8 +40,8 @@ const server = net.createServer(function(c) {
c.end();
this.close();
});
}).listen(common.PORT, function() {
net.connect(common.PORT, noop);
}).listen(0, function() {
net.connect(this.address().port, noop);
});
async_wrap.disable();

6
test/parallel/test-async-wrap-propagate-parent.js

@ -1,6 +1,6 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const net = require('net');
const async_wrap = process.binding('async_wrap');
@ -40,8 +40,8 @@ const server = net.createServer(function(c) {
c.end();
this.close();
});
}).listen(common.PORT, function() {
net.connect(common.PORT, noop);
}).listen(0, function() {
net.connect(this.address().port, noop);
});

4
test/parallel/test-beforeexit-event.js

@ -1,7 +1,7 @@
'use strict';
require('../common');
var assert = require('assert');
var net = require('net');
var common = require('../common');
var revivals = 0;
var deaths = 0;
@ -29,7 +29,7 @@ function tryTimer() {
function tryListen() {
console.log('create a server');
net.createServer()
.listen(common.PORT)
.listen(0)
.on('listening', function() {
revivals++;
this.close();

10
test/parallel/test-child-process-disconnect.js

@ -38,10 +38,10 @@ if (process.argv[2] === 'child') {
// when the server is ready tell parent
server.on('listening', function() {
process.send('ready');
process.send({ msg: 'ready', port: server.address().port });
});
server.listen(common.PORT);
server.listen(0);
} else {
// testcase
@ -65,11 +65,11 @@ if (process.argv[2] === 'child') {
});
// when child is listening
child.on('message', function(msg) {
if (msg === 'ready') {
child.on('message', function(obj) {
if (obj && obj.msg === 'ready') {
// connect to child using TCP to know if disconnect was emitted
var socket = net.connect(common.PORT);
var socket = net.connect(obj.port);
socket.on('data', function(data) {
data = data.toString();

4
test/parallel/test-child-process-fork-dgram.js

@ -72,7 +72,7 @@ if (process.argv[2] === 'child') {
msg,
0,
msg.length,
common.PORT,
server.address().port,
'127.0.0.1',
function(err) {
if (err) throw err;
@ -98,7 +98,7 @@ if (process.argv[2] === 'child') {
client.close();
};
server.bind(common.PORT, '127.0.0.1');
server.bind(0, '127.0.0.1');
process.once('exit', function() {
assert(parentGotMessage);

2
test/parallel/test-child-process-fork-net.js

@ -1,6 +1,6 @@
'use strict';
const assert = require('assert');
require('../common');
const assert = require('assert');
const fork = require('child_process').fork;
const net = require('net');

4
test/parallel/test-child-process-fork-net2.js

@ -99,7 +99,7 @@ if (process.argv[2] === 'child') {
var j = count, client;
while (j--) {
client = net.connect(common.PORT, '127.0.0.1');
client = net.connect(this.address().port, '127.0.0.1');
client.on('error', function() {
// This can happen if we kill the child too early.
// The client should still get a close event afterwards.
@ -125,7 +125,7 @@ if (process.argv[2] === 'child') {
child3.kill();
}));
server.listen(common.PORT, '127.0.0.1');
server.listen(0, '127.0.0.1');
var closeServer = function() {
server.close();

4
test/parallel/test-child-process-fork-regr-gh-2847.js

@ -25,11 +25,11 @@ var server = net.createServer(function(s) {
setTimeout(function() {
s.destroy();
}, 100);
}).listen(common.PORT, function() {
}).listen(0, function() {
var worker = cluster.fork();
function send(callback) {
var s = net.connect(common.PORT, function() {
var s = net.connect(server.address().port, function() {
worker.send({}, s, callback);
});

2
test/parallel/test-child-process-recv-handle.js

@ -24,7 +24,7 @@ function master() {
});
proc.stdout.on('data', function(data) {
assert.equal(data, 'ok\r\n');
net.createServer(common.fail).listen(common.PORT, function() {
net.createServer(common.fail).listen(0, function() {
handle = this._handle;
proc.send('one');
proc.send('two', handle);

4
test/parallel/test-child-process-send-keep-open.js

@ -37,8 +37,8 @@ if (process.argv[2] !== 'child') {
}));
});
server.listen(common.PORT, () => {
const socket = net.connect(common.PORT, common.localhostIPv4);
server.listen(0, () => {
const socket = net.connect(server.address().port, common.localhostIPv4);
socket.setEncoding('utf8');
socket.on('data', (data) => result += data);
});

2
test/parallel/test-child-process-send-returns-boolean.js

@ -20,7 +20,7 @@ s.on('exit', function() {
handle.close();
});
net.createServer(common.fail).listen(common.PORT, function() {
net.createServer(common.fail).listen(0, function() {
handle = this._handle;
assert.strictEqual(s.send('one', handle), true);
assert.strictEqual(s.send('two', handle), true);

4
test/parallel/test-crypto-verify-failure.js

@ -36,9 +36,9 @@ function verify() {
.verify(certPem, 'asdfasdfas', 'base64');
}
server.listen(common.PORT, function() {
server.listen(0, function() {
tls.connect({
port: common.PORT,
port: this.address().port,
rejectUnauthorized: false
}, function() {
verify();

12
test/parallel/test-dgram-address.js

@ -10,7 +10,9 @@ var family_ipv4 = 'IPv4';
socket_ipv4.on('listening', function() {
var address_ipv4 = socket_ipv4.address();
assert.strictEqual(address_ipv4.address, common.localhostIPv4);
assert.strictEqual(address_ipv4.port, common.PORT);
assert.strictEqual(typeof address_ipv4.port, 'number');
assert.ok(isFinite(address_ipv4.port));
assert.ok(address_ipv4.port > 0);
assert.strictEqual(address_ipv4.family, family_ipv4);
socket_ipv4.close();
});
@ -20,7 +22,7 @@ socket_ipv4.on('error', function(e) {
socket_ipv4.close();
});
socket_ipv4.bind(common.PORT, common.localhostIPv4);
socket_ipv4.bind(0, common.localhostIPv4);
// IPv6 Test
var localhost_ipv6 = '::1';
@ -30,7 +32,9 @@ var family_ipv6 = 'IPv6';
socket_ipv6.on('listening', function() {
var address_ipv6 = socket_ipv6.address();
assert.strictEqual(address_ipv6.address, localhost_ipv6);
assert.strictEqual(address_ipv6.port, common.PORT);
assert.strictEqual(typeof address_ipv6.port, 'number');
assert.ok(isFinite(address_ipv6.port));
assert.ok(address_ipv6.port > 0);
assert.strictEqual(address_ipv6.family, family_ipv6);
socket_ipv6.close();
});
@ -40,4 +44,4 @@ socket_ipv6.on('error', function(e) {
socket_ipv6.close();
});
socket_ipv6.bind(common.PORT, localhost_ipv6);
socket_ipv6.bind(0, localhost_ipv6);

12
test/parallel/test-dgram-bind-default-address.js

@ -9,8 +9,10 @@ if (common.inFreeBSDJail) {
return;
}
dgram.createSocket('udp4').bind(common.PORT + 0, common.mustCall(function() {
assert.equal(this.address().port, common.PORT + 0);
dgram.createSocket('udp4').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
assert.equal(this.address().address, '0.0.0.0');
this.close();
}));
@ -20,8 +22,10 @@ if (!common.hasIPv6) {
return;
}
dgram.createSocket('udp6').bind(common.PORT + 1, common.mustCall(function() {
assert.equal(this.address().port, common.PORT + 1);
dgram.createSocket('udp6').bind(0, common.mustCall(function() {
assert.strictEqual(typeof this.address().port, 'number');
assert.ok(isFinite(this.address().port));
assert.ok(this.address().port > 0);
var address = this.address().address;
if (address === '::ffff:0.0.0.0')
address = '::';

39
test/parallel/test-dgram-empty-packet.js

@ -13,27 +13,28 @@ if (process.platform === 'darwin') {
client = dgram.createSocket('udp4');
client.bind(common.PORT);
function callback() {
callbacks++;
if (callbacks == 2) {
clearTimeout(timer);
client.close();
} else if (callbacks > 2) {
throw new Error('the callbacks should be called only two times');
client.bind(0, function() {
function callback() {
callbacks++;
if (callbacks == 2) {
clearTimeout(timer);
client.close();
} else if (callbacks > 2) {
throw new Error('the callbacks should be called only two times');
}
}
}
client.on('message', function(buffer, bytes) {
callback();
});
client.send(
Buffer.allocUnsafe(1), 0, 0, common.PORT, '127.0.0.1', (err, len) => {
client.on('message', function(buffer, bytes) {
callback();
});
timer = setTimeout(function() {
throw new Error('Timeout');
}, 200);
const port = this.address().port;
client.send(
Buffer.allocUnsafe(1), 0, 0, port, '127.0.0.1', (err, len) => {
callback();
});
timer = setTimeout(function() {
throw new Error('Timeout');
}, 200);
});

12
test/parallel/test-dgram-error-message-address.js

@ -9,14 +9,14 @@ var socket_ipv4 = dgram.createSocket('udp4');
socket_ipv4.on('listening', common.fail);
socket_ipv4.on('error', common.mustCall(function(e) {
assert.equal(e.message, 'bind EADDRNOTAVAIL 1.1.1.1:' + common.PORT);
assert.strictEqual(e.port, undefined);
assert.equal(e.message, 'bind EADDRNOTAVAIL 1.1.1.1');
assert.equal(e.address, '1.1.1.1');
assert.equal(e.port, common.PORT);
assert.equal(e.code, 'EADDRNOTAVAIL');
socket_ipv4.close();
}));
socket_ipv4.bind(common.PORT, '1.1.1.1');
socket_ipv4.bind(0, '1.1.1.1');
// IPv6 Test
var socket_ipv6 = dgram.createSocket('udp6');
@ -27,10 +27,10 @@ socket_ipv6.on('error', common.mustCall(function(e) {
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
var allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
assert.notEqual(allowed.indexOf(e.code), -1);
assert.equal(e.message, 'bind ' + e.code + ' 111::1:' + common.PORT);
assert.strictEqual(e.port, undefined);
assert.equal(e.message, 'bind ' + e.code + ' 111::1');
assert.equal(e.address, '111::1');
assert.equal(e.port, common.PORT);
socket_ipv6.close();
}));
socket_ipv6.bind(common.PORT, '111::1');
socket_ipv6.bind(0, '111::1');

9
test/parallel/test-dgram-implicit-bind.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var dgram = require('dgram');
@ -22,8 +22,9 @@ target.on('message', function(buf) {
target.on('listening', function() {
// Second .send() call should not throw a bind error.
source.send(Buffer.from('abc'), 0, 3, common.PORT, '127.0.0.1');
source.send(Buffer.from('def'), 0, 3, common.PORT, '127.0.0.1');
const port = this.address().port;
source.send(Buffer.from('abc'), 0, 3, port, '127.0.0.1');
source.send(Buffer.from('def'), 0, 3, port, '127.0.0.1');
});
target.bind(common.PORT);
target.bind(0);

4
test/parallel/test-dgram-multicast-setTTL.js

@ -1,11 +1,11 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
let thrown = false;
socket.bind(common.PORT);
socket.bind(0);
socket.on('listening', function() {
socket.setMulticastTTL(16);

5
test/parallel/test-dgram-send-callback-multi-buffer.js

@ -19,7 +19,8 @@ const buf1 = Buffer.alloc(256, 'x');
const buf2 = Buffer.alloc(256, 'y');
client.on('listening', function() {
client.send([buf1, buf2], common.PORT, common.localhostIPv4, messageSent);
const port = this.address().port;
client.send([buf1, buf2], port, common.localhostIPv4, messageSent);
});
client.on('message', common.mustCall(function onMessage(buf, info) {
@ -28,4 +29,4 @@ client.on('message', common.mustCall(function onMessage(buf, info) {
client.close();
}));
client.bind(common.PORT);
client.bind(0);

8
test/parallel/test-dgram-send-callback-recursive.js

@ -9,17 +9,19 @@ let received = 0;
let sent = 0;
const limit = 10;
let async = false;
let port;
function onsend() {
if (sent++ < limit) {
client.send(
chunk, 0, chunk.length, common.PORT, common.localhostIPv4, onsend);
client.send(chunk, 0, chunk.length, port, common.localhostIPv4, onsend);
} else {
assert.strictEqual(async, true, 'Send should be asynchronous.');
}
}
client.on('listening', function() {
port = this.address().port;
setImmediate(function() {
async = true;
});
@ -38,4 +40,4 @@ client.on('close', common.mustCall(function() {
assert.equal(received, limit);
}));
client.bind(common.PORT);
client.bind(0);

11
test/parallel/test-dgram-send-default-host.js

@ -14,10 +14,11 @@ const toSend = [Buffer.alloc(256, 'x'),
const received = [];
client.on('listening', common.mustCall(() => {
client.send(toSend[0], 0, toSend[0].length, common.PORT);
client.send(toSend[1], common.PORT);
client.send([toSend[2]], common.PORT);
client.send(toSend[3], 0, toSend[3].length, common.PORT);
const port = client.address().port;
client.send(toSend[0], 0, toSend[0].length, port);
client.send(toSend[1], port);
client.send([toSend[2]], port);
client.send(toSend[3], 0, toSend[3].length, port);
}));
client.on('message', common.mustCall((buf, info) => {
@ -33,4 +34,4 @@ client.on('message', common.mustCall((buf, info) => {
}
}, toSend.length));
client.bind(common.PORT);
client.bind(0);

4
test/parallel/test-dgram-send-empty-array.js

@ -23,7 +23,7 @@ client.on('message', common.mustCall(function onMessage(buf, info) {
}));
client.on('listening', function() {
client.send([], common.PORT, common.localhostIPv4);
client.send([], this.address().port, common.localhostIPv4);
});
client.bind(common.PORT);
client.bind(0);

22
test/parallel/test-dgram-send-empty-buffer.js

@ -9,16 +9,18 @@ if (process.platform === 'darwin') {
const client = dgram.createSocket('udp4');
client.bind(common.PORT);
client.bind(0, function() {
const port = this.address().port;
client.on('message', common.mustCall(function onMessage(buffer, bytes) {
clearTimeout(timer);
client.close();
}));
client.on('message', common.mustCall(function onMessage(buffer, bytes) {
clearTimeout(timer);
client.close();
}));
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, common.PORT, '127.0.0.1', function(err, len) { });
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, port, '127.0.0.1', function(err, len) { });
const timer = setTimeout(function() {
throw new Error('Timeout');
}, common.platformTimeout(200));
const timer = setTimeout(function() {
throw new Error('Timeout');
}, common.platformTimeout(200));
});

4
test/parallel/test-dgram-send-multi-buffer-copy.js

@ -20,7 +20,7 @@ const buf2 = Buffer.alloc(256, 'y');
client.on('listening', function() {
const toSend = [buf1, buf2];
client.send(toSend, common.PORT, common.localhostIPv4, onMessage);
client.send(toSend, this.address().port, common.localhostIPv4, onMessage);
toSend.splice(0, 2);
});
@ -30,4 +30,4 @@ client.on('message', common.mustCall(function onMessage(buf, info) {
client.close();
}));
client.bind(common.PORT);
client.bind(0);

4
test/parallel/test-dgram-setBroadcast.js

@ -26,14 +26,14 @@ runTest((socket) => { socket.setBroadcast(true); }, /EBADF/);
// Should not throw if broadcast set to false after binding.
runTest((socket) => {
socket.bind(common.PORT, common.localhostIPv4, () => {
socket.bind(0, common.localhostIPv4, () => {
socket.setBroadcast(false);
});
});
// Should not throw if broadcast set to true after binding.
runTest((socket) => {
socket.bind(common.PORT, common.localhostIPv4, () => {
socket.bind(0, common.localhostIPv4, () => {
socket.setBroadcast(true);
});
});

4
test/parallel/test-dgram-setTTL.js

@ -1,10 +1,10 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.bind(common.PORT);
socket.bind(0);
socket.on('listening', function() {
var result = socket.setTTL(16);
assert.strictEqual(result, 16);

9
test/parallel/test-dgram-udp4.js

@ -2,7 +2,6 @@
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const server_port = common.PORT;
const message_to_send = 'A message to send';
const server = dgram.createSocket('udp4');
@ -13,9 +12,10 @@ server.on('message', common.mustCall((msg, rinfo) => {
}));
server.on('listening', common.mustCall(() => {
const client = dgram.createSocket('udp4');
const port = server.address().port;
client.on('message', common.mustCall((msg, rinfo) => {
assert.strictEqual(rinfo.address, common.localhostIPv4);
assert.strictEqual(rinfo.port, server_port);
assert.strictEqual(rinfo.port, port);
assert.strictEqual(msg.toString(), message_to_send.toString());
client.close();
server.close();
@ -23,10 +23,9 @@ server.on('listening', common.mustCall(() => {
client.send(message_to_send,
0,
message_to_send.length,
server_port,
port,
'localhost');
client.on('close', common.mustCall(() => {}));
}));
server.on('close', common.mustCall(() => {}));
server.bind(server_port);
server.bind(0);

11
test/parallel/test-dgram-udp6-send-default-host.js

@ -19,10 +19,11 @@ const toSend = [Buffer.alloc(256, 'x'),
const received = [];
client.on('listening', common.mustCall(() => {
client.send(toSend[0], 0, toSend[0].length, common.PORT);
client.send(toSend[1], common.PORT);
client.send([toSend[2]], common.PORT);
client.send(toSend[3], 0, toSend[3].length, common.PORT);
const port = client.address().port;
client.send(toSend[0], 0, toSend[0].length, port);
client.send(toSend[1], port);
client.send([toSend[2]], port);
client.send(toSend[3], 0, toSend[3].length, port);
}));
client.on('message', common.mustCall((buf, info) => {
@ -38,4 +39,4 @@ client.on('message', common.mustCall((buf, info) => {
}
}, toSend.length));
client.bind(common.PORT);
client.bind(0);

4
test/parallel/test-domain-abort-on-uncaught.js

@ -109,8 +109,8 @@ const tests = [
const server = net.createServer(function(conn) {
conn.pipe(conn);
});
server.listen(common.PORT, common.localhostIPv4, function() {
const conn = net.connect(common.PORT, common.localhostIPv4);
server.listen(0, common.localhostIPv4, function() {
const conn = net.connect(this.address().port, common.localhostIPv4);
conn.once('data', function() {
throw new Error('ok');
});

9
test/parallel/test-domain-http-server.js

@ -1,8 +1,8 @@
'use strict';
require('../common');
var domain = require('domain');
var http = require('http');
var assert = require('assert');
var common = require('../common');
var objects = { foo: 'bar', baz: {}, num: 42, arr: [1, 2, 3] };
objects.baz.asdf = objects;
@ -37,10 +37,11 @@ var server = http.createServer(function(req, res) {
});
});
server.listen(common.PORT, next);
server.listen(0, next);
function next() {
console.log('listening on localhost:%d', common.PORT);
const port = this.address().port;
console.log('listening on localhost:%d', port);
var requests = 0;
var responses = 0;
@ -61,7 +62,7 @@ function next() {
req.socket.destroy();
});
var req = http.get({ host: 'localhost', port: common.PORT, path: p });
var req = http.get({ host: 'localhost', port: port, path: p });
dom.add(req);
req.on('response', function(res) {
responses++;

32
test/parallel/test-domain-multi.js

@ -1,7 +1,7 @@
'use strict';
// Tests of multiple domains happening at once.
var common = require('../common');
require('../common');
var assert = require('assert');
var domain = require('domain');
@ -49,24 +49,24 @@ var server = http.createServer(function(req, res) {
throw new Error('this kills domain B, not A');
}));
}).listen(common.PORT);
}).listen(0, function() {
var c = domain.create();
var req = http.get({ host: 'localhost', port: this.address().port });
var c = domain.create();
var req = http.get({ host: 'localhost', port: common.PORT });
// add the request to the C domain
c.add(req);
// add the request to the C domain
c.add(req);
req.on('response', function(res) {
console.error('got response');
// add the response object to the C domain
c.add(res);
res.pipe(process.stdout);
});
req.on('response', function(res) {
console.error('got response');
// add the response object to the C domain
c.add(res);
res.pipe(process.stdout);
});
c.on('error', function(er) {
caughtC = true;
console.error('Error on c', er.message);
c.on('error', function(er) {
caughtC = true;
console.error('Error on c', er.message);
});
});
process.on('exit', function() {

2
test/parallel/test-handle-wrap-isrefed.js

@ -72,7 +72,7 @@ function makeAssert(message) {
{
const assert = makeAssert('hasRef() not working on tcp_wrap');
const net = require('net');
const server = net.createServer(() => {}).listen(common.PORT);
const server = net.createServer(() => {}).listen(0);
assert(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), true);
assert(server._handle.hasRef(), true);
assert(server._unref, false);

12
test/parallel/test-http-1.0-keep-alive.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
var net = require('net');
@ -84,14 +84,17 @@ check([{
function check(tests) {
var test = tests[0];
if (test) http.createServer(server).listen(common.PORT, '127.0.0.1', client);
var server;
if (test) {
server = http.createServer(serverHandler).listen(0, '127.0.0.1', client);
}
var current = 0;
function next() {
check(tests.slice(1));
}
function server(req, res) {
function serverHandler(req, res) {
if (current + 1 === test.responses.length) this.close();
var ctx = test.responses[current];
console.error('< SERVER SENDING RESPONSE', ctx);
@ -102,7 +105,8 @@ function check(tests) {
function client() {
if (current === test.requests.length) return next();
var conn = net.createConnection(common.PORT, '127.0.0.1', connected);
const port = server.address().port;
var conn = net.createConnection(port, '127.0.0.1', connected);
function connected() {
var ctx = test.requests[current];

7
test/parallel/test-http-1.0.js

@ -6,18 +6,15 @@ var http = require('http');
var body = 'hello world\n';
var common_port = common.PORT;
function test(handler, request_generator, response_validator) {
var port = common_port++;
var server = http.createServer(handler);
var client_got_eof = false;
var server_response = '';
server.listen(port);
server.listen(0);
server.on('listening', function() {
var c = net.createConnection(port);
var c = net.createConnection(this.address().port);
c.setEncoding('utf8');

10
test/parallel/test-http-abort-before-end.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
var assert = require('assert');
@ -7,8 +7,12 @@ var server = http.createServer(function(req, res) {
assert(false); // should not be called
});
server.listen(common.PORT, function() {
var req = http.request({method: 'GET', host: '127.0.0.1', port: common.PORT});
server.listen(0, function() {
var req = http.request({
method: 'GET',
host: '127.0.0.1',
port: this.address().port
});
req.on('error', function(ex) {
// https://github.com/joyent/node/issues/1399#issuecomment-2597359

7
test/parallel/test-http-abort-client.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
var assert = require('assert');
@ -13,11 +13,10 @@ var server = http.Server(function(req, res) {
var responseClose = false;
server.listen(common.PORT, function() {
server.listen(0, function() {
http.get({
port: common.PORT,
port: this.address().port,
headers: { connection: 'keep-alive' }
}, function(res) {
server.close();

4
test/parallel/test-http-abort-queued.js

@ -1,6 +1,6 @@
'use strict';
require('../common');
const assert = require('assert');
const common = require('../common');
const http = require('http');
var complete;
@ -19,7 +19,7 @@ var server = http.createServer(function(req, res) {
});
server.listen(common.PORT, function() {
server.listen(0, function() {
console.log('listen', server.address().port);
var agent = new http.Agent({maxSockets: 1});

8
test/parallel/test-http-after-connect.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -26,9 +26,9 @@ server.on('connect', function(req, socket, firstBodyChunk) {
socket.end();
});
});
server.listen(common.PORT, function() {
server.listen(0, function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'CONNECT',
path: 'google.com:80'
});
@ -46,7 +46,7 @@ server.listen(common.PORT, function() {
function doRequest(i) {
http.get({
port: common.PORT,
port: server.address().port,
path: '/request' + i
}, function(res) {
console.error('Client got GET response');

138
test/parallel/test-http-agent-destroyed-socket.js

@ -1,86 +1,86 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(common.PORT);
}).listen(0, function() {
var agent = new http.Agent({maxSockets: 1});
var agent = new http.Agent({maxSockets: 1});
agent.on('free', function(socket, host, port) {
console.log('freeing socket. destroyed? ', socket.destroyed);
});
agent.on('free', function(socket, host, port) {
console.log('freeing socket. destroyed? ', socket.destroyed);
});
var requestOptions = {
agent: agent,
host: 'localhost',
port: common.PORT,
path: '/'
};
var requestOptions = {
agent: agent,
host: 'localhost',
port: this.address().port,
path: '/'
};
var request1 = http.get(requestOptions, function(response) {
// assert request2 is queued in the agent
var key = agent.getName(requestOptions);
assert(agent.requests[key].length === 1);
console.log('got response1');
request1.socket.on('close', function() {
console.log('request1 socket closed');
});
response.pipe(process.stdout);
response.on('end', function() {
console.log('response1 done');
/////////////////////////////////
//
// THE IMPORTANT PART
//
// It is possible for the socket to get destroyed and other work
// to run before the 'close' event fires because it happens on
// nextTick. This example is contrived because it destroys the
// socket manually at just the right time, but at Voxer we have
// seen cases where the socket is destroyed by non-user code
// then handed out again by an agent *before* the 'close' event
// is triggered.
request1.socket.destroy();
var request1 = http.get(requestOptions, function(response) {
// assert request2 is queued in the agent
var key = agent.getName(requestOptions);
assert(agent.requests[key].length === 1);
console.log('got response1');
request1.socket.on('close', function() {
console.log('request1 socket closed');
});
response.pipe(process.stdout);
response.on('end', function() {
console.log('response1 done');
/////////////////////////////////
//
// THE IMPORTANT PART
//
// It is possible for the socket to get destroyed and other work
// to run before the 'close' event fires because it happens on
// nextTick. This example is contrived because it destroys the
// socket manually at just the right time, but at Voxer we have
// seen cases where the socket is destroyed by non-user code
// then handed out again by an agent *before* the 'close' event
// is triggered.
request1.socket.destroy();
response.once('close', function() {
// assert request2 was removed from the queue
assert(!agent.requests[key]);
console.log("waiting for request2.onSocket's nextTick");
process.nextTick(function() {
// assert that the same socket was not assigned to request2,
// since it was destroyed.
assert(request1.socket !== request2.socket);
assert(!request2.socket.destroyed, 'the socket is destroyed');
response.once('close', function() {
// assert request2 was removed from the queue
assert(!agent.requests[key]);
console.log("waiting for request2.onSocket's nextTick");
process.nextTick(function() {
// assert that the same socket was not assigned to request2,
// since it was destroyed.
assert(request1.socket !== request2.socket);
assert(!request2.socket.destroyed, 'the socket is destroyed');
});
});
});
});
});
var request2 = http.get(requestOptions, function(response) {
assert(!request2.socket.destroyed);
assert(request1.socket.destroyed);
// assert not reusing the same socket, since it was destroyed.
assert(request1.socket !== request2.socket);
console.log('got response2');
var gotClose = false;
var gotResponseEnd = false;
request2.socket.on('close', function() {
console.log('request2 socket closed');
gotClose = true;
done();
});
response.pipe(process.stdout);
response.on('end', function() {
console.log('response2 done');
gotResponseEnd = true;
done();
});
var request2 = http.get(requestOptions, function(response) {
assert(!request2.socket.destroyed);
assert(request1.socket.destroyed);
// assert not reusing the same socket, since it was destroyed.
assert(request1.socket !== request2.socket);
console.log('got response2');
var gotClose = false;
var gotResponseEnd = false;
request2.socket.on('close', function() {
console.log('request2 socket closed');
gotClose = true;
done();
});
response.pipe(process.stdout);
response.on('end', function() {
console.log('response2 done');
gotResponseEnd = true;
done();
});
function done() {
if (gotResponseEnd && gotClose)
server.close();
}
function done() {
if (gotResponseEnd && gotClose)
server.close();
}
});
});

52
test/parallel/test-http-agent-error-on-idle.js

@ -1,31 +1,27 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var Agent = http.Agent;
var agent = new Agent({
keepAlive: true,
var server = http.createServer(function(req, res) {
res.end('hello world');
});
var requestParams = {
host: 'localhost',
port: common.PORT,
agent: agent,
path: '/'
};
var socketKey = agent.getName(requestParams);
server.listen(0, function() {
var agent = new Agent({
keepAlive: true,
});
function get(callback) {
return http.get(requestParams, callback);
}
var requestParams = {
host: 'localhost',
port: this.address().port,
agent: agent,
path: '/'
};
var server = http.createServer(function(req, res) {
res.end('hello world');
});
var socketKey = agent.getName(requestParams);
server.listen(common.PORT, function() {
get(function(res) {
assert.equal(res.statusCode, 200);
res.resume();
@ -43,13 +39,17 @@ server.listen(common.PORT, function() {
});
});
});
});
function done() {
assert.equal(Object.keys(agent.freeSockets).length, 0,
'expect the freeSockets pool to be empty');
function get(callback) {
return http.get(requestParams, callback);
}
agent.destroy();
server.close();
process.exit(0);
}
function done() {
assert.equal(Object.keys(agent.freeSockets).length, 0,
'expect the freeSockets pool to be empty');
agent.destroy();
server.close();
process.exit(0);
}
});

9
test/parallel/test-http-agent-keepalive.js

@ -4,6 +4,8 @@ const assert = require('assert');
const http = require('http');
const Agent = require('_http_agent').Agent;
let name;
const agent = new Agent({
keepAlive: true,
keepAliveMsecs: 1000,
@ -28,14 +30,12 @@ const server = http.createServer(function(req, res) {
function get(path, callback) {
return http.get({
host: 'localhost',
port: common.PORT,
port: server.address().port,
agent: agent,
path: path
}, callback);
}
const name = 'localhost:' + common.PORT + ':';
function checkDataAndSockets(body) {
assert.equal(body.toString(), 'hello world');
assert.equal(agent.sockets[name].length, 1);
@ -106,7 +106,8 @@ function done() {
process.exit(0);
}
server.listen(common.PORT, function() {
server.listen(0, function() {
name = `localhost:${server.address().port}:`;
// request first, and keep alive
get('/first', function(res) {
assert.equal(res.statusCode, 200);

6
test/parallel/test-http-agent-maxsockets-regress-4050.js

@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const http = require('http');
@ -19,13 +19,13 @@ const server = http.createServer(function(req, res) {
function get(path, callback) {
return http.get({
host: 'localhost',
port: common.PORT,
port: server.address().port,
agent: agent,
path: path
}, callback);
}
server.listen(common.PORT, function() {
server.listen(0, function() {
var finished = 0;
const num_requests = 6;
for (var i = 0; i < num_requests; i++) {

6
test/parallel/test-http-agent-maxsockets.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -17,7 +17,7 @@ var server = http.createServer(function(req, res) {
function get(path, callback) {
return http.get({
host: 'localhost',
port: common.PORT,
port: server.address().port,
agent: agent,
path: path
}, callback);
@ -35,7 +35,7 @@ function done() {
server.close();
}
server.listen(common.PORT, function() {
server.listen(0, function() {
get('/1', function(res) {
assert.equal(res.statusCode, 200);
res.resume();

6
test/parallel/test-http-agent-no-protocol.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var url = require('url');
@ -14,8 +14,8 @@ process.on('exit', function() {
var server = http.createServer(function(req, res) {
res.end();
request++;
}).listen(common.PORT, '127.0.0.1', function() {
var opts = url.parse('http://127.0.0.1:' + common.PORT + '/');
}).listen(0, '127.0.0.1', function() {
var opts = url.parse(`http://127.0.0.1:${this.address().port}/`);
// remove the `protocol` field… the `http` module should fall back
// to "http:", as defined by the global, default `http.Agent` instance.

4
test/parallel/test-http-agent-null.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -13,7 +13,7 @@ process.on('exit', function() {
var server = http.createServer(function(req, res) {
request++;
res.end();
}).listen(common.PORT, function() {
}).listen(0, function() {
var options = {
agent: null,
port: this.address().port

7
test/parallel/test-http-agent.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -12,11 +12,12 @@ var responses = 0;
var N = 4;
var M = 4;
server.listen(common.PORT, function() {
server.listen(0, function() {
const port = this.address().port;
for (var i = 0; i < N; i++) {
setTimeout(function() {
for (var j = 0; j < M; j++) {
http.get({ port: common.PORT, path: '/' }, function(res) {
http.get({ port: port, path: '/' }, function(res) {
console.log('%d %d', responses, res.statusCode);
if (++responses == N * M) {
console.error('Received all responses, closing server');

6
test/parallel/test-http-allow-req-after-204-res.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
var assert = require('assert');
@ -23,7 +23,7 @@ function nextRequest() {
console.error('writing request: %s', method);
var request = http.request({
port: common.PORT,
port: server.address().port,
method: method,
path: '/'
}, function(response) {
@ -43,4 +43,4 @@ function nextRequest() {
request.end();
}
server.listen(common.PORT, nextRequest);
server.listen(0, nextRequest);

8
test/parallel/test-http-automatic-headers.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -9,12 +9,12 @@ var server = http.createServer(function(req, res) {
res.setHeader('X-Content-Length', 'baz');
res.end();
});
server.listen(common.PORT);
server.listen(0);
server.on('listening', function() {
var agent = new http.Agent({ port: common.PORT, maxSockets: 1 });
var agent = new http.Agent({ port: this.address().port, maxSockets: 1 });
http.get({
port: common.PORT,
port: this.address().port,
path: '/hello',
agent: agent
}, function(res) {

19
test/parallel/test-http-bind-twice.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -14,14 +14,13 @@ function dontCall() {
}
var server1 = http.createServer(dontCall);
server1.listen(common.PORT, '127.0.0.1', function() {});
server1.listen(0, '127.0.0.1', function() {
var server2 = http.createServer(dontCall);
server2.listen(this.address().port, '127.0.0.1', dontCall);
var server2 = http.createServer(dontCall);
server2.listen(common.PORT, '127.0.0.1', dontCall);
server2.on('error', function(e) {
assert.equal(e.code, 'EADDRINUSE');
server1.close();
gotError = true;
server2.on('error', function(e) {
assert.equal(e.code, 'EADDRINUSE');
server1.close();
gotError = true;
});
});

6
test/parallel/test-http-blank-header.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var net = require('net');
@ -18,8 +18,8 @@ var server = http.createServer(function(req, res) {
});
server.listen(common.PORT, function() {
var c = net.createConnection(common.PORT);
server.listen(0, function() {
var c = net.createConnection(this.address().port);
c.on('connect', function() {
c.write('GET /blah HTTP/1.1\r\n' +

6
test/parallel/test-http-buffer-sanity.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -44,11 +44,11 @@ var web = http.Server(function(req, res) {
var gotThanks = false;
web.listen(common.PORT, function() {
web.listen(0, function() {
console.log('Making request');
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'GET',
path: '/',
headers: { 'content-length': buffer.length }

6
test/parallel/test-http-byteswritten.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -36,6 +36,6 @@ var httpServer = http.createServer(function(req, res) {
res.end(body);
});
httpServer.listen(common.PORT, function() {
http.get({ port: common.PORT });
httpServer.listen(0, function() {
http.get({ port: this.address().port });
});

4
test/parallel/test-http-catch-uncaughtexception.js

@ -13,8 +13,8 @@ process.on('uncaughtException', uncaughtCallback);
const server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('bye');
}).listen(common.PORT, function() {
http.get({ port: common.PORT }, function(res) {
}).listen(0, function() {
http.get({ port: this.address().port }, function(res) {
res.resume();
throw new Error('get did fail');
}).on('close', function() {

8
test/parallel/test-http-chunk-problem.js

@ -10,7 +10,7 @@ if (!common.hasCrypto) {
if (process.argv[2] === 'request') {
const http = require('http');
const options = {
port: common.PORT,
port: +process.argv[3],
path: '/'
};
@ -39,11 +39,13 @@ const http = require('http');
const cp = require('child_process');
const filename = require('path').join(common.tmpDir, 'big');
let server;
function executeRequest(cb) {
cp.exec([process.execPath,
__filename,
'request',
server.address().port,
'|',
process.execPath,
__filename,
@ -64,7 +66,7 @@ const ddcmd = common.ddCommand(filename, 10240);
cp.exec(ddcmd, function(err, stdout, stderr) {
if (err) throw err;
const server = http.createServer(function(req, res) {
server = http.createServer(function(req, res) {
res.writeHead(200);
// Create the subprocess
@ -87,7 +89,7 @@ cp.exec(ddcmd, function(err, stdout, stderr) {
});
server.listen(common.PORT, () => {
server.listen(0, () => {
executeRequest(() => server.close());
});
});

4
test/parallel/test-http-chunked-304.js

@ -23,8 +23,8 @@ function test(statusCode, next) {
server.close();
});
server.listen(common.PORT, function() {
var conn = net.createConnection(common.PORT, function() {
server.listen(0, function() {
var conn = net.createConnection(this.address().port, function() {
conn.write('GET / HTTP/1.1\r\n\r\n');
var resp = '';

6
test/parallel/test-http-chunked.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -17,12 +17,12 @@ var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'});
res.end(UTF8_STRING, 'utf8');
});
server.listen(common.PORT, function() {
server.listen(0, function() {
var data = '';
var get = http.get({
path: '/',
host: 'localhost',
port: common.PORT
port: this.address().port
}, function(x) {
x.setEncoding('utf8');
x.on('data', function(c) {data += c;});

6
test/parallel/test-http-client-abort-event.js

@ -1,14 +1,14 @@
'use strict';
require('../common');
var assert = require('assert');
var http = require('http');
var common = require('../common');
var server = http.createServer(function(req, res) {
res.end();
});
var count = 0;
server.listen(common.PORT, function() {
server.listen(0, function() {
var req = http.request({
port: common.PORT
port: this.address().port
}, function() {
assert(false, 'should not receive data');
});

6
test/parallel/test-http-client-abort.js

@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const http = require('http');
@ -27,12 +27,12 @@ var responses = 0;
const N = 8;
const requests = [];
server.listen(common.PORT, function() {
server.listen(0, function() {
console.log('Server listening.');
for (var i = 0; i < N; i++) {
console.log('Making client ' + i);
var options = { port: common.PORT, path: '/?id=' + i };
var options = { port: this.address().port, path: '/?id=' + i };
var req = http.get(options, function(res) {
console.log('Client response code ' + res.statusCode);

6
test/parallel/test-http-client-abort2.js

@ -1,13 +1,13 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
var server = http.createServer(function(req, res) {
res.end('Hello');
});
server.listen(common.PORT, function() {
var req = http.get({port: common.PORT}, function(res) {
server.listen(0, function() {
var req = http.get({port: this.address().port}, function(res) {
res.on('data', function(data) {
req.abort();
server.close();

9
test/parallel/test-http-client-agent.js

@ -1,9 +1,9 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var name = http.globalAgent.getName({ port: common.PORT });
var name;
var max = 3;
var count = 0;
@ -18,7 +18,8 @@ var server = http.Server(function(req, res) {
res.end('Hello, World!');
}
});
server.listen(common.PORT, function() {
server.listen(0, function() {
name = http.globalAgent.getName({ port: this.address().port });
for (var i = 0; i < max; ++i) {
request(i);
}
@ -26,7 +27,7 @@ server.listen(common.PORT, function() {
function request(i) {
var req = http.get({
port: common.PORT,
port: server.address().port,
path: '/' + i
}, function(res) {
var socket = req.socket;

6
test/parallel/test-http-client-default-headers-exist.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -36,11 +36,11 @@ var server = http.createServer(function(req, res) {
server.close();
});
server.listen(common.PORT, function() {
server.listen(0, function() {
expectedMethods.forEach(function(method) {
http.request({
method: method,
port: common.PORT
port: server.address().port
}).end();
});
});

6
test/parallel/test-http-client-encoding.js

@ -1,16 +1,16 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
http.createServer(function(req, res) {
res.end('ok\n');
this.close();
}).listen(common.PORT, test);
}).listen(0, test);
function test() {
http.request({
port: common.PORT,
port: this.address().port,
encoding: 'utf8'
}, function(res) {
res.pipe(process.stdout);

6
test/parallel/test-http-client-get-url.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -15,8 +15,8 @@ var server = http.createServer(function(req, res) {
seen_req = true;
});
server.listen(common.PORT, function() {
http.get('http://127.0.0.1:' + common.PORT + '/foo?bar');
server.listen(0, function() {
http.get(`http://127.0.0.1:${this.address().port}/foo?bar`);
});
process.on('exit', function() {

6
test/parallel/test-http-client-parse-error.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -17,11 +17,11 @@ net.createServer(function(c) {
c.end('bad http - should trigger parse error\r\n');
this.close();
}
}).listen(common.PORT, '127.0.0.1', function() {
}).listen(0, '127.0.0.1', function() {
for (var i = 0; i < 2; i++) {
http.request({
host: '127.0.0.1',
port: common.PORT,
port: this.address().port,
method: 'GET',
path: '/'
}).on('error', function(e) {

8
test/parallel/test-http-client-race-2.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var url = require('url');
@ -27,14 +27,14 @@ var server = http.createServer(function(req, res) {
{'Content-Type': 'text/plain', 'Content-Length': body.length});
res.end(body);
});
server.listen(common.PORT);
server.listen(0);
var body1 = '';
var body2 = '';
var body3 = '';
server.on('listening', function() {
var client = http.createClient(common.PORT);
var client = http.createClient(this.address().port);
//
// Client #1 is assigned Parser #1
@ -59,7 +59,7 @@ server.on('listening', function() {
// parser that previously belonged to Client #1. But we're not finished
// with Client #1 yet!
//
var client2 = http.createClient(common.PORT);
var client2 = http.createClient(server.address().port);
//
// At this point, the bug would manifest itself and crash because the

8
test/parallel/test-http-client-race.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var url = require('url');
@ -13,13 +13,13 @@ var server = http.createServer(function(req, res) {
{'Content-Type': 'text/plain', 'Content-Length': body.length});
res.end(body);
});
server.listen(common.PORT);
server.listen(0);
var body1 = '';
var body2 = '';
server.on('listening', function() {
var req1 = http.request({ port: common.PORT, path: '/1' });
var req1 = http.request({ port: this.address().port, path: '/1' });
req1.end();
req1.on('response', function(res1) {
res1.setEncoding('utf8');
@ -29,7 +29,7 @@ server.on('listening', function() {
});
res1.on('end', function() {
var req2 = http.request({ port: common.PORT, path: '/2' });
var req2 = http.request({ port: server.address().port, path: '/2' });
req2.end();
req2.on('response', function(res2) {
res2.setEncoding('utf8');

4
test/parallel/test-http-client-reject-chunked-with-content-length.js

@ -13,11 +13,11 @@ const server = net.createServer((socket) => {
socket.write(reqstr);
});
server.listen(common.PORT, () => {
server.listen(0, () => {
// The callback should not be called because the server is sending
// both a Content-Length header and a Transfer-Encoding: chunked
// header, which is a violation of the HTTP spec.
const req = http.get({port: common.PORT}, (res) => {
const req = http.get({port: server.address().port}, (res) => {
assert.fail(null, null, 'callback should not be called');
});
req.on('error', common.mustCall((err) => {

4
test/parallel/test-http-client-reject-cr-no-lf.js

@ -13,10 +13,10 @@ const server = net.createServer((socket) => {
socket.write(reqstr);
});
server.listen(common.PORT, () => {
server.listen(0, () => {
// The callback should not be called because the server is sending a
// header field that ends only in \r with no following \n
const req = http.get({port: common.PORT}, (res) => {
const req = http.get({port: server.address().port}, (res) => {
assert.fail(null, null, 'callback should not be called');
});
req.on('error', common.mustCall((err) => {

7
test/parallel/test-http-client-timeout-agent.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -8,7 +8,7 @@ var requests_sent = 0;
var requests_done = 0;
var options = {
method: 'GET',
port: common.PORT,
port: undefined,
host: '127.0.0.1',
};
@ -27,7 +27,8 @@ var server = http.createServer(function(req, res) {
request_number += 1;
});
server.listen(options.port, options.host, function() {
server.listen(0, options.host, function() {
options.port = this.address().port;
var req;
for (requests_sent = 0; requests_sent < 30; requests_sent += 1) {

5
test/parallel/test-http-client-timeout-event.js

@ -5,7 +5,7 @@ var http = require('http');
var options = {
method: 'GET',
port: common.PORT,
port: undefined,
host: '127.0.0.1',
path: '/'
};
@ -14,7 +14,8 @@ var server = http.createServer(function(req, res) {
// this space intentionally left blank
});
server.listen(options.port, options.host, function() {
server.listen(0, options.host, function() {
options.port = this.address().port;
var req = http.request(options, function(res) {
// this space intentionally left blank
});

5
test/parallel/test-http-client-timeout-with-data.js

@ -13,7 +13,7 @@ process.on('exit', function() {
const options = {
method: 'GET',
port: common.PORT,
port: undefined,
host: '127.0.0.1',
path: '/'
};
@ -24,7 +24,8 @@ const server = http.createServer(function(req, res) {
setTimeout(function() { res.end('*'); }, common.platformTimeout(100));
});
server.listen(options.port, options.host, function() {
server.listen(0, options.host, function() {
options.port = this.address().port;
const req = http.request(options, onresponse);
req.end();

7
test/parallel/test-http-client-timeout.js

@ -1,11 +1,11 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var options = {
method: 'GET',
port: common.PORT,
port: undefined,
host: '127.0.0.1',
path: '/'
};
@ -14,7 +14,8 @@ var server = http.createServer(function(req, res) {
// this space intentionally left blank
});
server.listen(options.port, options.host, function() {
server.listen(0, options.host, function() {
options.port = this.address().port;
var req = http.request(options, function(res) {
// this space intentionally left blank
});

6
test/parallel/test-http-client-upload-buf.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -23,11 +23,11 @@ var server = http.createServer(function(req, res) {
res.end();
});
});
server.listen(common.PORT);
server.listen(0);
server.on('listening', function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'POST',
path: '/'
}, function(res) {

6
test/parallel/test-http-client-upload.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -24,11 +24,11 @@ var server = http.createServer(function(req, res) {
res.end();
});
});
server.listen(common.PORT);
server.listen(0);
server.on('listening', function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'POST',
path: '/'
}, function(res) {

7
test/parallel/test-http-conn-reset.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var net = require('net');
@ -8,7 +8,7 @@ var caughtError = false;
var options = {
host: '127.0.0.1',
port: common.PORT
port: undefined
};
// start a tcp server that closes incoming connections immediately
@ -16,10 +16,11 @@ var server = net.createServer(function(client) {
client.destroy();
server.close();
});
server.listen(options.port, options.host, onListen);
server.listen(0, options.host, onListen);
// do a GET request, expect it to fail
function onListen() {
options.port = this.address().port;
var req = http.request(options, function(res) {
assert.ok(false, 'this should never run');
});

6
test/parallel/test-http-connect-req-res.js

@ -28,9 +28,9 @@ server.on('connect', common.mustCall(function(req, socket, firstBodyChunk) {
socket.end(data);
});
}));
server.listen(common.PORT, common.mustCall(function() {
server.listen(0, common.mustCall(function() {
const req = http.request({
port: common.PORT,
port: this.address().port,
method: 'CONNECT',
path: 'example.com:443'
}, function(res) {
@ -43,7 +43,7 @@ server.listen(common.PORT, common.mustCall(function() {
console.error('Client got CONNECT request');
// Make sure this request got removed from the pool.
const name = 'localhost:' + common.PORT;
const name = 'localhost:' + server.address().port;
assert(!http.globalAgent.sockets.hasOwnProperty(name));
assert(!http.globalAgent.requests.hasOwnProperty(name));

8
test/parallel/test-http-connect.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -25,9 +25,9 @@ server.on('connect', function(req, socket, firstBodyChunk) {
socket.end(data);
});
});
server.listen(common.PORT, function() {
server.listen(0, function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'CONNECT',
path: 'google.com:443'
}, function(res) {
@ -44,7 +44,7 @@ server.listen(common.PORT, function() {
clientGotConnect = true;
// Make sure this request got removed from the pool.
var name = 'localhost:' + common.PORT;
var name = 'localhost:' + server.address().port;
assert(!http.globalAgent.sockets.hasOwnProperty(name));
assert(!http.globalAgent.requests.hasOwnProperty(name));

10
test/parallel/test-http-content-length.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -46,11 +46,11 @@ var server = http.createServer(function(req, res) {
if (totalRequests === receivedRequests) server.close();
});
server.listen(common.PORT, function() {
server.listen(0, function() {
var req;
req = http.request({
port: common.PORT,
port: this.address().port,
method: 'POST',
path: '/multiple-writes'
});
@ -63,7 +63,7 @@ server.listen(common.PORT, function() {
});
req = http.request({
port: common.PORT,
port: this.address().port,
method: 'POST',
path: '/end-with-data'
});
@ -75,7 +75,7 @@ server.listen(common.PORT, function() {
});
req = http.request({
port: common.PORT,
port: this.address().port,
method: 'POST',
path: '/empty'
});

6
test/parallel/test-http-contentLength0.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
// Simple test of Node's HTTP Client choking on a response
@ -11,9 +11,9 @@ var s = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Length': '0 '});
res.end();
});
s.listen(common.PORT, function() {
s.listen(0, function() {
var request = http.request({ port: common.PORT }, function(response) {
var request = http.request({ port: this.address().port }, function(response) {
console.log('STATUS: ' + response.statusCode);
s.close();
response.resume();

10
test/parallel/test-http-createConnection.js

@ -6,7 +6,7 @@ const assert = require('assert');
const server = http.createServer(common.mustCall(function(req, res) {
res.end();
}, 4)).listen(common.PORT, '127.0.0.1', function() {
}, 4)).listen(0, '127.0.0.1', function() {
let fn = common.mustCall(createConnection);
http.get({ createConnection: fn }, function(res) {
res.resume();
@ -33,17 +33,17 @@ const server = http.createServer(common.mustCall(function(req, res) {
});
function createConnection() {
return net.createConnection(common.PORT, '127.0.0.1');
return net.createConnection(server.address().port, '127.0.0.1');
}
function createConnectionAsync(options, cb) {
setImmediate(function() {
cb(null, net.createConnection(common.PORT, '127.0.0.1'));
cb(null, net.createConnection(server.address().port, '127.0.0.1'));
});
}
function createConnectionBoth1(options, cb) {
const socket = net.createConnection(common.PORT, '127.0.0.1');
const socket = net.createConnection(server.address().port, '127.0.0.1');
setImmediate(function() {
cb(null, socket);
});
@ -51,7 +51,7 @@ function createConnectionBoth1(options, cb) {
}
function createConnectionBoth2(options, cb) {
const socket = net.createConnection(common.PORT, '127.0.0.1');
const socket = net.createConnection(server.address().port, '127.0.0.1');
cb(null, socket);
return socket;
}

6
test/parallel/test-http-date-header.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -13,12 +13,12 @@ var server = http.createServer(function(req, res) {
});
res.end(testResBody);
});
server.listen(common.PORT);
server.listen(0);
server.addListener('listening', function() {
var options = {
port: common.PORT,
port: this.address().port,
path: '/',
method: 'GET'
};

6
test/parallel/test-http-default-encoding.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -18,9 +18,9 @@ var server = http.Server(function(req, res) {
});
server.listen(common.PORT, function() {
server.listen(0, function() {
http.request({
port: common.PORT,
port: this.address().port,
path: '/',
method: 'POST'
}, function(res) {

18
test/parallel/test-http-default-port.js

@ -1,8 +1,6 @@
'use strict';
const common = require('../common');
const http = require('http');
const PORT = common.PORT;
const SSLPORT = common.PORT + 1;
const assert = require('assert');
const hostExpect = 'localhost';
const fs = require('fs');
@ -29,18 +27,18 @@ process.on('exit', function() {
console.log('ok');
});
http.globalAgent.defaultPort = PORT;
http.createServer(function(req, res) {
assert.equal(req.headers.host, hostExpect);
assert.equal(req.headers['x-port'], PORT);
assert.equal(req.headers['x-port'], this.address().port);
res.writeHead(200);
res.end('ok');
this.close();
}).listen(PORT, function() {
}).listen(0, function() {
http.globalAgent.defaultPort = this.address().port;
http.get({
host: 'localhost',
headers: {
'x-port': PORT
'x-port': this.address().port
}
}, function(res) {
gotHttpResp = true;
@ -49,19 +47,19 @@ http.createServer(function(req, res) {
});
if (common.hasCrypto) {
https.globalAgent.defaultPort = SSLPORT;
https.createServer(options, function(req, res) {
assert.equal(req.headers.host, hostExpect);
assert.equal(req.headers['x-port'], SSLPORT);
assert.equal(req.headers['x-port'], this.address().port);
res.writeHead(200);
res.end('ok');
this.close();
}).listen(SSLPORT, function() {
}).listen(0, function() {
https.globalAgent.defaultPort = this.address().port;
https.get({
host: 'localhost',
rejectUnauthorized: false,
headers: {
'x-port': SSLPORT
'x-port': this.address().port
}
}, function(res) {
gotHttpsResp = true;

4
test/parallel/test-http-destroyed-socket-write2.js

@ -12,9 +12,9 @@ var server = http.createServer(function(req, res) {
});
});
server.listen(common.PORT, function() {
server.listen(0, function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
path: '/',
method: 'POST'
});

4
test/parallel/test-http-double-content-length.js

@ -17,9 +17,9 @@ server.on('clientError', common.mustCall((err, socket) => {
socket.destroy();
}));
server.listen(common.PORT, () => {
server.listen(0, () => {
const req = http.get({
port: common.PORT,
port: server.address().port,
// Send two content-length header values.
headers: {'Content-Length': [1, 2]}},
(res) => {

4
test/parallel/test-http-end-throw-socket-handling.js

@ -16,9 +16,9 @@ const server = http.createServer((req, res) => {
res.end('ok');
});
server.listen(common.PORT, common.mustCall(() => {
server.listen(0, common.mustCall(() => {
for (let i = 0; i < 10; i++) {
const options = { port: common.PORT };
const options = { port: server.address().port };
const req = http.request(options, (res) => {
res.resume();
res.on('end', common.mustCall(() => {

6
test/parallel/test-http-eof-on-connect.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var net = require('net');
var http = require('http');
@ -8,10 +8,10 @@ var http = require('http');
// reproduceable on the first packet on the first connection to a server.
var server = http.createServer(function(req, res) {});
server.listen(common.PORT);
server.listen(0);
server.on('listening', function() {
net.createConnection(common.PORT).on('connect', function() {
net.createConnection(this.address().port).on('connect', function() {
this.destroy();
}).on('close', function() {
server.close();

6
test/parallel/test-http-exceptions.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
var server = http.createServer(function(req, res) {
@ -9,9 +9,9 @@ var server = http.createServer(function(req, res) {
res.end();
});
server.listen(common.PORT, function() {
server.listen(0, function() {
for (var i = 0; i < 4; i += 1) {
http.get({ port: common.PORT, path: '/busy/' + i });
http.get({ port: this.address().port, path: '/busy/' + i });
}
});

6
test/parallel/test-http-expect-continue.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -28,12 +28,12 @@ server.on('checkContinue', function(req, res) {
handler(req, res);
}, 100);
});
server.listen(common.PORT);
server.listen(0);
server.on('listening', function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'POST',
path: '/world',
headers: { 'Expect': '100-continue' }

4
test/parallel/test-http-expect-handling.js

@ -13,11 +13,11 @@ const s = http.createServer(function(req, res) {
throw new Error('this should never be executed');
});
s.listen(common.PORT, nextTest);
s.listen(0, nextTest);
function nextTest() {
const options = {
port: common.PORT,
port: s.address().port,
headers: { 'Expect': 'meoww' }
};

6
test/parallel/test-http-extra-response.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var net = require('net');
@ -44,8 +44,8 @@ var server = net.createServer(function(socket) {
});
server.listen(common.PORT, function() {
http.get({ port: common.PORT }, function(res) {
server.listen(0, function() {
http.get({ port: this.address().port }, function(res) {
var buffer = '';
console.log('Got res code: ' + res.statusCode);

6
test/parallel/test-http-flush-headers.js

@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const http = require('http');
@ -9,11 +9,11 @@ server.on('request', function(req, res) {
res.end('ok');
server.close();
});
server.listen(common.PORT, '127.0.0.1', function() {
server.listen(0, '127.0.0.1', function() {
const req = http.request({
method: 'GET',
host: '127.0.0.1',
port: common.PORT,
port: this.address().port,
});
req.setHeader('foo', 'bar');
req.flushHeaders();

4
test/parallel/test-http-flush-response-headers.js

@ -10,11 +10,11 @@ server.on('request', function(req, res) {
res.flushHeaders();
res.flushHeaders(); // Should be idempotent.
});
server.listen(common.PORT, common.localhostIPv4, function() {
server.listen(0, common.localhostIPv4, function() {
var req = http.request({
method: 'GET',
host: common.localhostIPv4,
port: common.PORT,
port: this.address().port,
}, onResponse);
req.end();

6
test/parallel/test-http-flush.js

@ -1,15 +1,15 @@
'use strict';
var common = require('../common');
require('../common');
var http = require('http');
http.createServer(function(req, res) {
res.end('ok');
this.close();
}).listen(common.PORT, '127.0.0.1', function() {
}).listen(0, '127.0.0.1', function() {
var req = http.request({
method: 'POST',
host: '127.0.0.1',
port: common.PORT,
port: this.address().port,
});
req.flush(); // Flush the request headers.
req.flush(); // Should be idempotent.

4
test/parallel/test-http-full-response.js

@ -20,7 +20,7 @@ var server = http.createServer(function(req, res) {
var runs = 0;
function runAb(opts, callback) {
var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/';
var command = `ab ${opts} http://127.0.0.1:${server.address().port}/`;
exec(command, function(err, stdout, stderr) {
if (err) {
if (/ab|apr/mi.test(stderr)) {
@ -49,7 +49,7 @@ function runAb(opts, callback) {
});
}
server.listen(common.PORT, function() {
server.listen(0, function() {
runAb('-c 1 -n 10', function() {
console.log('-c 1 -n 10 okay');

4
test/parallel/test-http-get-pipeline-problem.js

@ -34,13 +34,13 @@ var server = http.Server(function(req, res) {
});
server.listen(common.PORT, function() {
server.listen(0, function() {
for (var i = 0; i < total; i++) {
(function() {
var x = i;
var opts = {
port: common.PORT,
port: server.address().port,
headers: { connection: 'close' }
};

10
test/parallel/test-http-head-request.js

@ -1,15 +1,11 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
var body = 'hello world\n';
var id = 0;
function test(headers) {
var port = common.PORT + id++;
var server = http.createServer(function(req, res) {
console.error('req: %s headers: %j', req.method, headers);
res.writeHead(200, headers);
@ -19,9 +15,9 @@ function test(headers) {
var gotEnd = false;
server.listen(port, function() {
server.listen(0, function() {
var request = http.request({
port: port,
port: this.address().port,
method: 'HEAD',
path: '/'
}, function(response) {

6
test/parallel/test-http-head-response-has-no-body-end.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -12,13 +12,13 @@ var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('FAIL'); // broken: sends FAIL from hot path.
});
server.listen(common.PORT);
server.listen(0);
var responseComplete = false;
server.on('listening', function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'HEAD',
path: '/'
}, function(res) {

6
test/parallel/test-http-head-response-has-no-body.js

@ -1,5 +1,5 @@
'use strict';
var common = require('../common');
require('../common');
var assert = require('assert');
var http = require('http');
@ -12,13 +12,13 @@ var server = http.createServer(function(req, res) {
res.writeHead(200); // broken: defaults to TE chunked
res.end();
});
server.listen(common.PORT);
server.listen(0);
var responseComplete = false;
server.on('listening', function() {
var req = http.request({
port: common.PORT,
port: this.address().port,
method: 'HEAD',
path: '/'
}, function(res) {

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save