Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(launcher): exit code is always 100 for sharded and 1 for nonshard…
Browse files Browse the repository at this point in the history
…ed tests
  • Loading branch information
hankduan committed Oct 28, 2014
1 parent f645252 commit 7283fdf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
54 changes: 36 additions & 18 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ var log_ = function() {
* @param {Object=} additionalConfig
*/
var init = function(configFile, additionalConfig) {

var runnerErrorCount = 0;

var configParser = new ConfigParser();
if (configFile) {
configParser.addFileConfig(configFile);
Expand Down Expand Up @@ -101,16 +98,21 @@ var init = function(configFile, additionalConfig) {
this.process.on('error', function(err) {
self.reporter.flush();
log_('Runner Process(' + self.process.pid + ') Error: ' + err);
runnerErrorCount += 1;
self.reporter.exitCode = RUNNERS_FAILED_EXIT_CODE;
});

this.process.on('exit', function(code) {
self.reporter.flush();
if (code) {
log_('Runner Process Exited With Error Code: ' + code);
runnerErrorCount += 1;
if (self.reporter.failedCount) {
log_('Test runner exited with ' + self.reporter.failedCount +
' failed test(s)');
} else {
log_('Runner process exited unexpectedly with error code: ' + code);
}
}
self.reporter.exitCode = code;

if (typeof testsDoneCallback === 'function') {
testsDoneCallback();
}
Expand Down Expand Up @@ -162,7 +164,7 @@ var init = function(configFile, additionalConfig) {
cleanUpAndExit(exitCode);
}).catch(function(err) {
log_('Error:', err.stack || err.message || err);
cleanUpAndExit(1);
cleanUpAndExit(RUNNERS_FAILED_EXIT_CODE);
});
} else {
if (config.debug) {
Expand Down Expand Up @@ -193,21 +195,21 @@ var init = function(configFile, additionalConfig) {
deferred.promise.then(function() {
reporter.reportSummary();
var exitCode = 0;
if (runnerErrorCount > 0) {
if (reporter.totalProcessFailures() > 0) {
exitCode = RUNNERS_FAILED_EXIT_CODE;
} else if (reporter.totalSpecFailures() > 0) {
exitCode = 1;
}
return cleanUpAndExit(exitCode);
});

process.on('exit', function(code) {

if (code && code != RUNNERS_FAILED_EXIT_CODE) {
if (code) {
log_('Process exited with error code ' + code);
} else if (!code &&
scheduler.numTasksOutstanding() > 0) {
code = 1;
log_('BUG: launcher exited with ' +
scheduler.numTasksOutstanding() + ' tasks remaining');
} else if (scheduler.numTasksOutstanding() > 0) {
code = RUNNERS_FAILED_EXIT_CODE;
log_('BUG: launcher exited with ' +
scheduler.numTasksOutstanding() + ' tasks remaining');
}
process.exit(code);
});
Expand All @@ -229,20 +231,36 @@ var reporter = {
return taskReporter;
},

reportSummary: function() {
totalSpecFailures: function() {
var specFailures = 0;
this.taskReporters_.forEach(function(taskReporter) {
specFailures += taskReporter.failedCount;
});
return specFailures;
},

totalProcessFailures: function() {
var processFailures = 0;
this.taskReporters_.forEach(function(taskReporter) {
if (!taskReporter.failedCount && taskReporter.exitCode !== 0) {
processFailures += 1;
}
});
return processFailures;
},

reportSummary: function() {
var specFailures = this.totalSpecFailures();
var processFailures = this.totalProcessFailures();
this.taskReporters_.forEach(function(taskReporter) {
var capability = taskReporter.task.capability;
var shortName = (capability.browserName) ? capability.browserName : '';
shortName += (capability.version) ? capability.version : '';
shortName += (' #' + taskReporter.task.taskId);
if (taskReporter.failedCount) {
log_(shortName + ' failed ' + taskReporter.failedCount + ' test(s)');
specFailures += taskReporter.failedCount;
} else if (taskReporter.exitCode !== 0) {
log_(shortName + ' failed with exit code: ' + taskReporter.exitCode);
processFailures += 1;
} else {
log_(shortName + ' passed');
}
Expand Down
12 changes: 7 additions & 5 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ Runner.prototype.run = function() {
this.setTestPreparer(this.config_.onPrepare);

var gracefulShutdown = function(driver) {
return driver.getSession().then(function(session_) {
if (session_) {
return driver.quit();
}
});
if (driver) {
return driver.getSession().then(function(session_) {
if (session_) {
return driver.quit();
}
});
}
};

// 1) Setup environment
Expand Down

0 comments on commit 7283fdf

Please sign in to comment.