Skip to content

Commit

Permalink
test: remove common.PORT from gc tests
Browse files Browse the repository at this point in the history
Allow the operating system to provide an arbitrary available port rather
than using `common.PORT`, as `common.PORT` makes it likely that a test
will fail with `EADDRINUSE` as a side effect of an earlier test.

PR-URL: #7013
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
Trott authored and Myles Borins committed Jul 14, 2016
1 parent 15bb0be commit 44228df
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
7 changes: 3 additions & 4 deletions test/gc/test-http-client-connaborted.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const common = require('../common');
require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
Expand All @@ -19,7 +18,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');

var server = http.createServer(serverHandler);
server.listen(PORT, getall);
server.listen(0, getall);

function getall() {
if (count >= todo)
Expand All @@ -34,7 +33,7 @@ function getall() {
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
port: server.address().port
}, cb).on('error', cb);

count++;
Expand Down
7 changes: 3 additions & 4 deletions test/gc/test-http-client-onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const common = require('../common');
require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
Expand All @@ -21,7 +20,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');

var server = http.createServer(serverHandler);
server.listen(PORT, runTest);
server.listen(0, runTest);

function getall() {
if (count >= todo)
Expand All @@ -40,7 +39,7 @@ function getall() {
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
port: server.address().port
}, cb).on('error', onerror);

count++;
Expand Down
7 changes: 3 additions & 4 deletions test/gc/test-http-client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const common = require('../common');
require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 550;
let done = 0;
let count = 0;
Expand All @@ -23,7 +22,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');

var server = http.createServer(serverHandler);
server.listen(PORT, getall);
server.listen(0, getall);

function getall() {
if (count >= todo)
Expand All @@ -39,7 +38,7 @@ function getall() {
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
port: server.address().port
}, cb);
req.on('error', cb);
req.setTimeout(10, function() {
Expand Down
7 changes: 3 additions & 4 deletions test/gc/test-http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ function serverHandler(req, res) {

const http = require('http');
const weak = require('weak');
const common = require('../common');
require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
Expand All @@ -19,7 +18,7 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');

var server = http.createServer(serverHandler);
server.listen(PORT, getall);
server.listen(0, getall);


function getall() {
Expand All @@ -37,7 +36,7 @@ function getall() {
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
port: server.address().port
}, cb);

count++;
Expand Down
7 changes: 3 additions & 4 deletions test/gc/test-net-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ function serverHandler(sock) {

const net = require('net');
const weak = require('weak');
const common = require('../common');
require('../common');
const assert = require('assert');
const PORT = common.PORT;
const todo = 500;
let done = 0;
let count = 0;
Expand All @@ -30,14 +29,14 @@ let countGC = 0;
console.log('We should do ' + todo + ' requests');

var server = net.createServer(serverHandler);
server.listen(PORT, getall);
server.listen(0, getall);

function getall() {
if (count >= todo)
return;

(function() {
var req = net.connect(PORT, '127.0.0.1');
var req = net.connect(server.address().port, server.address().address);
req.resume();
req.setTimeout(10, function() {
//console.log('timeout (expected)')
Expand Down

0 comments on commit 44228df

Please sign in to comment.