Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function cleanUpAndExit(signal, status) {

function getTestBrowserInfo(browserString, path) {
var info = browserString;
if(config.multipleTest) {
if (config.multipleTest) {
info += ", " + path;
}
return info;
Expand Down Expand Up @@ -145,7 +145,7 @@ function launchBrowser(browser, path) {
}

timeout = parseInt(config.timeout);
if(! isNaN(timeout)) {
if (!isNaN(timeout)) {
browser.timeout = timeout;
} else {
timeout = 300;
Expand All @@ -166,6 +166,7 @@ function launchBrowser(browser, path) {
worker.config = browser;
worker.string = browserString;
worker.test_path = path;
worker.path_index = 0;
workers[key] = worker;
workerKeys[worker.id] = {key: key, marked: false};
});
Expand All @@ -174,11 +175,9 @@ function launchBrowser(browser, path) {

function launchBrowsers(config, browser) {
setTimeout(function () {
if(Object.prototype.toString.call(config.test_path) === '[object Array]'){
if (Object.prototype.toString.call(config.test_path) === '[object Array]'){
config.multipleTest = config.test_path.length > 1? true : false;
config.test_path.forEach(function(path){
launchBrowser(browser, path);
});
launchBrowser(browser, config.test_path[0]);
} else {
config.multipleTest = false;
launchBrowser(browser, config.test_path);
Expand Down Expand Up @@ -277,8 +276,8 @@ function runTests() {
launchServer();
tunnel = new Tunnel(config.key, serverPort, config.tunnelIdentifier, function () {
statusPoller.start();
var total_workers = config.browsers.length * (Object.prototype.toString.call(config.test_path) === '[object Array]' ? config.test_path.length : 1);
logger.info("Launching " + total_workers + " workers");
var total_runs = config.browsers.length * (Object.prototype.toString.call(config.test_path) === '[object Array]' ? config.test_path.length : 1);
logger.info("Launching " + config.browsers.length + " worker(s) for " + total_runs + " run(s).");
browsers.forEach(function(browser) {
if (browser.browser_version === "latest") {
logger.debug("[%s] Finding version.", utils.browserString(browser));
Expand Down
2 changes: 2 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var commit_id = process.env.TRAVIS_COMMIT;

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

['username', 'key', 'test_path', 'browsers'].forEach(function(param) {
Expand Down
29 changes: 28 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,27 @@ exports.Server = function Server(bsClient, workers) {
return details;
}

function checkAndTerminateWorker(worker, callback) {
var next_path = getNextTestPath(worker);
if (next_path) {
var new_url = 'http://localhost:' + 8888 + '/' + next_path
+ "?_worker_key=" + worker._worker_key + "&_browser_string=" + getTestBrowserInfo(worker) ;
worker.test_path = next_path;
bsClient.changeUrl(worker.id, {url: new_url}, function() {
callback(true);
});
} else {
bsClient.terminateWorker(worker.id, callback);
}
};

function getNextTestPath(worker) {
if (!config.multipleTest) {
return null;
}
return config.test_path[ ++worker.path_index ];
}

handlers = {
"_progress": function progressHandler(uri, body, request, response) {
var uuid = request.headers['x-worker-uuid'];
Expand Down Expand Up @@ -184,6 +205,7 @@ exports.Server = function Server(bsClient, workers) {
} catch (e) {}
var uuid = request.headers['x-worker-uuid'];
var worker = workers[uuid] || {};
worker._worker_key = uuid;

if (query === null) {
logger.info("[%s] Null response from remote Browser", request.headers['x-browser-string']);
Expand All @@ -205,11 +227,16 @@ exports.Server = function Server(bsClient, workers) {
logger.info('[%s] ' + chalk['yellow']('Screenshot') + ': %s', getTestBrowserInfo(worker), screenshot.url);
}

bsClient.terminateWorker(worker.id, function() {
checkAndTerminateWorker(worker, function(reusedWorker) {
if (!workers[uuid]) {
return;
}

if (reusedWorker) {
logger.debug('[%s] Reused', getTestBrowserInfo(worker));
return;
}

logger.debug('[%s] Terminated', getTestBrowserInfo(worker));

clearTimeout(workers[uuid].activityTimeout);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/browserstack/browserstack-runner.git"
},
"dependencies": {
"browserstack": "1.0.1",
"browserstack": "1.1.0",
"chalk": "0.4.0",
"tunnel": "0.0.3"
},
Expand Down