Skip to content

Commit

Permalink
Added support to configure the async timeout for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed May 24, 2016
1 parent 17fe8e9 commit 1c3e489
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,4 @@ Runner.prototype.run = function runner() {

processListener();

module.exports = Runner;
module.exports = Runner;
4 changes: 3 additions & 1 deletion lib/runner/testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var Q = require('q');
var Logger = require('../util/logger.js');
var Utils = require('../util/utils.js');
var Reporter = require('../runner/reporter.js');
var DEFAULT_UNITTEST_HOOK_TIMEOUT = 2000;

function TestCase(suite, testFn, numRetries, maxRetries) {
this.suite = suite;
Expand All @@ -13,6 +14,7 @@ function TestCase(suite, testFn, numRetries, maxRetries) {
this._deferredNext = null;
this.running = false;
this.lastTimerId = null;
this.asyncHookTimeout = this.suite.client.globals('asyncHookTimeout') || DEFAULT_UNITTEST_HOOK_TIMEOUT;
}

TestCase.prototype.print = function () {
Expand Down Expand Up @@ -107,7 +109,7 @@ TestCase.prototype.run = function () {
};

TestCase.prototype.setDoneCallbackTimer = function(done, fnName, onTimerStarted) {
return Utils.setCallbackTimeout(done, fnName, 2000, function(err) {
return Utils.setCallbackTimeout(done, fnName, this.asyncHookTimeout, function(err) {
throw err;
}, onTimerStarted);
};
Expand Down
6 changes: 6 additions & 0 deletions test/asynchookstests/unittest-async-timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

module.exports = {
demoTest : function (done) {

}
};
2 changes: 1 addition & 1 deletion test/src/runner/testRunWithHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module.exports = {
persist_globals : true,
globals: globals
}, {
output_folder: false,
output_folder: false,
start_session: true
}, function (err, results) {
if (err) {
Expand Down
34 changes: 32 additions & 2 deletions test/src/runner/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,38 @@ module.exports = {
runner.run().catch(function (err) {
done(err);
});
}
}
},

'test async unit test with timeout error': function (done) {
var testsPath = path.join(__dirname, '../../asynchookstests/unittest-async-timeout.js');
var globals = {
calls : 0,
asyncHookTimeout: 10
};

process.on('uncaughtException', function (err) {
assert.ok(err instanceof Error);
assert.equal(err.message, 'done() callback timeout of 10 ms was reached while executing "demoTest". ' +
'Make sure to call the done() callback when the operation finishes.');

done();
});

var runner = new Runner([testsPath], {
seleniumPort: 10195,
silent: true,
output: false,
persist_globals : true,
globals: globals,
compatible_testcase_support : true
}, {
output_folder : false,
start_session : false
});

runner.run().catch(function(err) {
done(err);
});
}
}
};
3 changes: 1 addition & 2 deletions test/src/util/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Utils = common.require('util/utils.js');
module.exports = {
'test Utils' : {
testFormatElapsedTime : function() {

var resultMs = Utils.formatElapsedTime(999);
assert.equal(resultMs, '999ms');

Expand Down Expand Up @@ -62,4 +62,3 @@ module.exports = {
}
}
};

0 comments on commit 1c3e489

Please sign in to comment.