Skip to content

Commit 8f936a4

Browse files
committed
Fix worker reuse
1 parent af6b40b commit 8f936a4

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

bin/cli.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ var Log = require('../lib/logger'),
3232
timeout,
3333
activityTimeout,
3434
workers = {},
35-
browserToWorker = {},
3635
workerKeys = {},
3736
logLevel,
3837
tunnelingAgent,
@@ -105,7 +104,7 @@ function cleanUpAndExit(signal, status) {
105104

106105
function getTestBrowserInfo(browserString, path) {
107106
var info = browserString;
108-
if(config.multipleTest) {
107+
if (config.multipleTest) {
109108
info += ", " + path;
110109
}
111110
return info;
@@ -146,7 +145,7 @@ function launchBrowser(browser, path) {
146145
}
147146

148147
timeout = parseInt(config.timeout);
149-
if(! isNaN(timeout)) {
148+
if (!isNaN(timeout)) {
150149
browser.timeout = timeout;
151150
} else {
152151
timeout = 300;
@@ -167,6 +166,7 @@ function launchBrowser(browser, path) {
167166
worker.config = browser;
168167
worker.string = browserString;
169168
worker.test_path = path;
169+
worker.path_index = 0;
170170
workers[key] = worker;
171171
workerKeys[worker.id] = {key: key, marked: false};
172172
});
@@ -175,15 +175,9 @@ function launchBrowser(browser, path) {
175175

176176
function launchBrowsers(config, browser) {
177177
setTimeout(function () {
178-
if(Object.prototype.toString.call(config.test_path) === '[object Array]'){
178+
if (Object.prototype.toString.call(config.test_path) === '[object Array]'){
179179
config.multipleTest = config.test_path.length > 1? true : false;
180-
if(config.reuseWorker) {
181-
launchBrowser(browser, config.test_path[0]);
182-
} else {
183-
config.test_path.forEach(function(path){
184-
launchBrowser(browser, path);
185-
});
186-
}
180+
launchBrowser(browser, config.test_path[0]);
187181
} else {
188182
config.multipleTest = false;
189183
launchBrowser(browser, config.test_path);
@@ -282,8 +276,8 @@ function runTests() {
282276
launchServer();
283277
tunnel = new Tunnel(config.key, serverPort, config.tunnelIdentifier, function () {
284278
statusPoller.start();
285-
var total_workers = config.browsers.length * (Object.prototype.toString.call(config.test_path) === '[object Array]' ? config.test_path.length : 1);
286-
logger.info("Launching " + total_workers + " workers");
279+
var total_runs = config.browsers.length * (Object.prototype.toString.call(config.test_path) === '[object Array]' ? config.test_path.length : 1);
280+
logger.info("Launching " + config.browsers.length + " worker(s) for " + total_runs + " run(s).");
287281
browsers.forEach(function(browser) {
288282
if (browser.browser_version === "latest") {
289283
logger.debug("[%s] Finding version.", utils.browserString(browser));

lib/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var commit_id = process.env.TRAVIS_COMMIT;
4949

5050
if (commit_id) {
5151
config.build = "Commit-" + commit_id.slice(0, commit_id.length / 2);
52+
} {
53+
config.build = "Local run, " + new Date().toISOString();
5254
}
5355

5456
['username', 'key', 'test_path', 'browsers'].forEach(function(param) {

lib/server.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,24 @@ exports.Server = function Server(bsClient, workers) {
158158
}
159159

160160
function checkAndTerminateWorker(worker, callback) {
161-
if(config.reuseWorker && config.multipleTest) {
162-
var next_path = getNextTestPath(worker.test_path);
161+
var next_path = getNextTestPath(worker);
162+
if (next_path) {
163163
var new_url = 'http://localhost:' + 8888 + '/' + next_path
164-
+ "_worker_key=" + worker._worker_key + "&_browser_string=" + getTestBrowserInfo(worker) ;
165-
bsClient.postNewUrl(worker.id, {url: new_url}, function() {
164+
+ "?_worker_key=" + worker._worker_key + "&_browser_string=" + getTestBrowserInfo(worker) ;
165+
worker.test_path = next_path;
166+
bsClient.changeUrl(worker.id, {url: new_url}, function() {
166167
callback(true);
167168
});
168169
} else {
169170
bsClient.terminateWorker(worker.id, callback);
170171
}
171172
};
172173

173-
function getNextTestPath(test_path) {
174-
// Someday I'll die for codes like these
175-
for(var i = 0; i < config.test_path.length; i++) {
176-
if(config.test_path[i] == test_path) {
177-
return config.test_path[ i + 1 ];
178-
}
174+
function getNextTestPath(worker) {
175+
if (!config.multipleTest) {
176+
return null;
179177
}
180-
178+
return config.test_path[ ++worker.path_index ];
181179
}
182180

183181
handlers = {
@@ -234,7 +232,7 @@ exports.Server = function Server(bsClient, workers) {
234232
return;
235233
}
236234

237-
if(reusedWorker) {
235+
if (reusedWorker) {
238236
logger.debug('[%s] Reused', getTestBrowserInfo(worker));
239237
return;
240238
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/browserstack/browserstack-runner.git"
99
},
1010
"dependencies": {
11-
"browserstack": "1.0.1",
11+
"browserstack": "1.1.0",
1212
"chalk": "0.4.0",
1313
"tunnel": "0.0.3"
1414
},

0 commit comments

Comments
 (0)