Skip to content

Commit 84187b6

Browse files
committed
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.
1 parent 5d6482b commit 84187b6

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/browser-stack/start-tunnel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var http = require('http');
33
var BrowserStackTunnel = require('browserstacktunnel-wrapper');
44

55
var HOSTNAME = 'localhost';
6-
var PORTS = [9090, 9876];
6+
var PORTS = require('../grunt/utils').availablePorts;
77
var ACCESS_KEY = process.env.BROWSER_STACK_ACCESS_KEY;
88
var READY_FILE = process.env.SAUCE_CONNECT_READY_FILE;
99

lib/grunt/utils.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ var spawn = require('child_process').spawn;
55
var version;
66
var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n';
77

8+
var PORT_MIN = 8000;
9+
var PORT_MAX = 9999;
10+
var TRAVIS_BUILD_NUMBER = parseInt(process.env.TRAVIS_BUILD_NUMBER, 10);
11+
var getRandomPorts = function() {
12+
if (!process.env.TRAVIS) {
13+
return [9876, 9877];
14+
}
15+
16+
// Generate two numbers between PORT_MIN and PORT_MAX, based on TRAVIS_BUILD_NUMBER.
17+
return [
18+
PORT_MIN + (TRAVIS_BUILD_NUMBER % (PORT_MAX - PORT_MIN)),
19+
PORT_MIN + ((TRAVIS_BUILD_NUMBER + 100) % (PORT_MAX - PORT_MIN))
20+
];
21+
};
22+
23+
824
module.exports = {
925

1026
init: function() {
@@ -279,7 +295,7 @@ module.exports = {
279295
stream: options && options.stream
280296
};
281297

282-
args.push('--port=' + this.sauceLabsAvailablePorts.pop());
298+
args.push('--port=' + this.availablePorts.pop());
283299

284300
if (args.indexOf('test:e2e') !== -1 && grunt.option('e2e-browsers')) {
285301
args.push('--browsers=' + grunt.option('e2e-browsers'));
@@ -295,5 +311,7 @@ module.exports = {
295311
},
296312

297313
// see http://saucelabs.com/docs/connect#localhost
298-
sauceLabsAvailablePorts: [9000, 9001, 9080, 9090, 9876]
314+
sauceLabsAvailablePorts: [9000, 9001, 9080, 9090, 9876],
315+
// pseudo-random port numbers for BrowserStack
316+
availablePorts: getRandomPorts()
299317
};

0 commit comments

Comments
 (0)