summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-proxy.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2016-05-29 03:06:56 -0400
committerBrian White <mscdex@mscdex.net>2016-06-10 22:30:55 -0400
commit2bc7841d0fcdd066fe477873229125b6f003b693 (patch)
tree2816555ef6ad2fc828a75dc3c564f8faa2dee6c7 /test/parallel/test-http-proxy.js
parent624734e640717a826ab1a18845c083a638dc5ce6 (diff)
downloadandroid-node-v8-2bc7841d0fcdd066fe477873229125b6f003b693.tar.gz
android-node-v8-2bc7841d0fcdd066fe477873229125b6f003b693.tar.bz2
android-node-v8-2bc7841d0fcdd066fe477873229125b6f003b693.zip
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>
Diffstat (limited to 'test/parallel/test-http-proxy.js')
-rw-r--r--test/parallel/test-http-proxy.js13
1 files changed, 5 insertions, 8 deletions
diff --git a/test/parallel/test-http-proxy.js b/test/parallel/test-http-proxy.js
index aec8eaa14c..43feb1e3b3 100644
--- a/test/parallel/test-http-proxy.js
+++ b/test/parallel/test-http-proxy.js
@@ -1,12 +1,9 @@
'use strict';
-var common = require('../common');
+require('../common');
var assert = require('assert');
var http = require('http');
var url = require('url');
-var PROXY_PORT = common.PORT;
-var BACKEND_PORT = common.PORT + 1;
-
var cookies = [
'session_token=; path=/; expires=Sun, 15-Sep-2030 13:48:52 GMT',
'prefers_open_id=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT'
@@ -26,7 +23,7 @@ var backend = http.createServer(function(req, res) {
var proxy = http.createServer(function(req, res) {
console.error('proxy req headers: ' + JSON.stringify(req.headers));
http.get({
- port: BACKEND_PORT,
+ port: backend.address().port,
path: url.parse(req.url).pathname
}, function(proxy_res) {
@@ -57,7 +54,7 @@ function startReq() {
if (nlistening < 2) return;
http.get({
- port: PROXY_PORT,
+ port: proxy.address().port,
path: '/test'
}, function(res) {
console.error('got res');
@@ -79,10 +76,10 @@ function startReq() {
}
console.error('listen proxy');
-proxy.listen(PROXY_PORT, startReq);
+proxy.listen(0, startReq);
console.error('listen backend');
-backend.listen(BACKEND_PORT, startReq);
+backend.listen(0, startReq);
process.on('exit', function() {
assert.equal(body, 'hello world\n');