From d51c856f11aad43f8c43d77630e035c9f11c2d73 Mon Sep 17 00:00:00 2001 From: Yosuke Saito Date: Sat, 12 Nov 2016 16:47:27 +0900 Subject: [PATCH] test: fix test-http-status-reason-invalid-chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use port 0 instead of common.PORT, and use server address instead of localhost to follow writing test guideline. This is a part of Code And Learn at NodeFest 2016 Challenge in Tokyo. PR-URL: https://github.com/nodejs/node/pull/9572 Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso Reviewed-By: Santiago Gimeno Reviewed-By: Shigeki Ohtsu Reviewed-By: James M Snell --- test/parallel/test-http-status-reason-invalid-chars.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-status-reason-invalid-chars.js b/test/parallel/test-http-status-reason-invalid-chars.js index 7a8564a906131a..245822d0146975 100644 --- a/test/parallel/test-http-status-reason-invalid-chars.js +++ b/test/parallel/test-http-status-reason-invalid-chars.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); +const net = require('net'); function explicit(req, res) { assert.throws(() => { @@ -32,8 +33,10 @@ const server = http.createServer((req, res) => { } else { implicit(req, res); } -}).listen(common.PORT, common.mustCall(() => { - const url = `http://localhost:${common.PORT}`; +}).listen(0, common.mustCall(() => { + const addr = server.address().address; + const hostname = net.isIPv6(addr) ? `[${addr}1]` : addr; + const url = `http://${hostname}:${server.address().port}`; let left = 2; const check = common.mustCall((res) => { left--;