From 84187b6d94179edf04512038f68c14f34a8e6219 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 3 Dec 2013 09:58:30 -0800 Subject: chore(travis): use different port numbers per build We can't establish multiple SSH tunnels for the same port (for BrowserStack). This makes it possible to run multiple parallel builds using BrowserStack. --- lib/browser-stack/start-tunnel.js | 2 +- lib/grunt/utils.js | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/browser-stack/start-tunnel.js b/lib/browser-stack/start-tunnel.js index f2b475d8..87230b68 100644 --- a/lib/browser-stack/start-tunnel.js +++ b/lib/browser-stack/start-tunnel.js @@ -3,7 +3,7 @@ var http = require('http'); var BrowserStackTunnel = require('browserstacktunnel-wrapper'); var HOSTNAME = 'localhost'; -var PORTS = [9090, 9876]; +var PORTS = require('../grunt/utils').availablePorts; var ACCESS_KEY = process.env.BROWSER_STACK_ACCESS_KEY; var READY_FILE = process.env.SAUCE_CONNECT_READY_FILE; diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 90613a29..49d346a0 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -5,6 +5,22 @@ var spawn = require('child_process').spawn; var version; var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n'; +var PORT_MIN = 8000; +var PORT_MAX = 9999; +var TRAVIS_BUILD_NUMBER = parseInt(process.env.TRAVIS_BUILD_NUMBER, 10); +var getRandomPorts = function() { + if (!process.env.TRAVIS) { + return [9876, 9877]; + } + + // Generate two numbers between PORT_MIN and PORT_MAX, based on TRAVIS_BUILD_NUMBER. + return [ + PORT_MIN + (TRAVIS_BUILD_NUMBER % (PORT_MAX - PORT_MIN)), + PORT_MIN + ((TRAVIS_BUILD_NUMBER + 100) % (PORT_MAX - PORT_MIN)) + ]; +}; + + module.exports = { init: function() { @@ -279,7 +295,7 @@ module.exports = { stream: options && options.stream }; - args.push('--port=' + this.sauceLabsAvailablePorts.pop()); + args.push('--port=' + this.availablePorts.pop()); if (args.indexOf('test:e2e') !== -1 && grunt.option('e2e-browsers')) { args.push('--browsers=' + grunt.option('e2e-browsers')); @@ -295,5 +311,7 @@ module.exports = { }, // see http://saucelabs.com/docs/connect#localhost - sauceLabsAvailablePorts: [9000, 9001, 9080, 9090, 9876] + sauceLabsAvailablePorts: [9000, 9001, 9080, 9090, 9876], + // pseudo-random port numbers for BrowserStack + availablePorts: getRandomPorts() }; -- cgit v1.2.3