Skip to content

Commit

Permalink
Merge branch 'issues/671-fix-parallel-exit-code'
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Oct 13, 2015
2 parents b6bc6c0 + 5604395 commit 0e699a8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/runner/cli/clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ CliRunner.prototype = {

startEnvChildren : function(envs, availColors, args, doneCallback) {
var self = this;
var globalExitCode = 0;

envs.forEach(function(environment, index) {
self.childProcessOutput[environment] = [];
Expand All @@ -708,12 +709,14 @@ CliRunner.prototype = {
child.setLabel(environment + ' environment');
self.runningProcesses[child.itemKey] = child;
self.runningProcesses[child.itemKey].run(availColors, function(output, exitCode) {
if (exitCode > 0) {
globalExitCode = exitCode;
}
if (self.processesRunning() === 0) {
if (!self.settings.live_output) {
self.printChildProcessOutput();
}

doneCallback(exitCode || 0);
doneCallback(globalExitCode);
}
});
});
Expand Down
26 changes: 26 additions & 0 deletions tests/extra/parallelism-envs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"src_folders" : ["./sampletests"],
"output_folder" : false,
"output" : false,

"selenium" : {
"start_process" : false
},

"test_settings" : {
"default" : {
"silent" : true,
"desiredCapabilities" : {
"browserName" : "firefox"
}
},
"env1" : {
"filter" : "mixed/*"
},
"env2" : {
"filter" : "simple/*"
}
}
}


31 changes: 26 additions & 5 deletions tests/src/runner/testParallelExecutionExitCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module.exports = {
this.allArgs = [];
this.allOpts = [];
var self = this;

var index = 0;
mockery.enable({ useCleanCache: true, warnOnUnregistered: false });
mockery.registerMock('child_process', {
execFile : function(path, args, opts) {
self.allArgs.push(args);
self.allOpts.push(opts);

function Stdout() {}
function Stderr() {}

Expand All @@ -26,7 +26,7 @@ module.exports = {
this.stderr = new Stderr();
setTimeout(function() {
this.emit('close');
this.emit('exit', 1);
this.emit('exit', index == 0 ? 1 : 0);
}.bind(this), 11);
};

Expand All @@ -40,7 +40,7 @@ module.exports = {
});
mockery.registerMock('os', {
cpus : function() {
return [0, 1];
return [0, 1, 2];
}
});

Expand All @@ -55,7 +55,7 @@ module.exports = {
callback();
},

testParallelExecutionWithCodeNonZero : function(test) {
testParallelExecutionWithCodeNonZeroWorkers : function(test) {
var CliRunner = require('../../../' + BASE_PATH + '/../lib/runner/cli/clirunner.js');
var runner = new CliRunner({
config : './extra/parallelism-count.json'
Expand All @@ -70,6 +70,27 @@ module.exports = {
process.exit = originalExit;
};

runner.setup({}, function(output, code) {
test.equals(code, 1);
});
},

testParallelExecutionWithCodeNonZeroEnvs : function(test) {
var CliRunner = require('../../../' + BASE_PATH + '/../lib/runner/cli/clirunner.js');
var runner = new CliRunner({
config : './extra/parallelism-envs.json',
env : 'env1,env2'
});

test.expect(2);

var originalExit = process.exit;
process.exit = function(code) {
test.equals(code, 1);
test.done();
process.exit = originalExit;
};

runner.setup({}, function(output, code) {
test.equals(code, 1);
});
Expand Down

0 comments on commit 0e699a8

Please sign in to comment.