Make all async functions be subject to the timeout
[finishes #60798058]
This commit is contained in:
@@ -230,9 +230,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
this.description = attrs.description || '';
|
this.description = attrs.description || '';
|
||||||
this.fn = attrs.fn;
|
this.fn = attrs.fn;
|
||||||
this.beforeFns = attrs.beforeFns || function() {};
|
this.beforeFns = attrs.beforeFns || function() { return []; };
|
||||||
this.afterFns = attrs.afterFns || function() {};
|
this.afterFns = attrs.afterFns || function() { return []; };
|
||||||
this.catchingExceptions = attrs.catchingExceptions;
|
|
||||||
this.onStart = attrs.onStart || function() {};
|
this.onStart = attrs.onStart || function() {};
|
||||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||||
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
||||||
@@ -297,13 +296,15 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
timeout = void 0;
|
timeout = void 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var befores = this.beforeFns() || [],
|
var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns()),
|
||||||
afters = this.afterFns() || [],
|
allTimeoutableFns = [];
|
||||||
thisOne = (this.fn.length) ? timeoutable(this.fn) : this.fn;
|
for (var i = 0; i < allFns.length; i++) {
|
||||||
var allFns = befores.concat(thisOne).concat(afters);
|
var fn = allFns[i];
|
||||||
|
allTimeoutableFns.push(fn.length > 0 ? timeoutable(fn) : fn);
|
||||||
|
}
|
||||||
|
|
||||||
this.queueRunnerFactory({
|
this.queueRunnerFactory({
|
||||||
fns: allFns,
|
fns: allTimeoutableFns,
|
||||||
onException: onException,
|
onException: onException,
|
||||||
onComplete: complete
|
onComplete: complete
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -218,12 +218,37 @@ describe("Spec", function() {
|
|||||||
expect(specNameSpy.calls.mostRecent().args[0].id).toEqual(spec.id);
|
expect(specNameSpy.calls.mostRecent().args[0].id).toEqual(spec.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resets the timeout timer when an async spec throws an exception", function() {
|
it("sets a timeout for async functions to keep them from running forever", function() {
|
||||||
|
var queueRunnerSpy = jasmine.createSpy('queue runner'),
|
||||||
|
setTimeoutSpy = jasmine.createSpy('setTimeout'),
|
||||||
|
spec = new j$.Spec({
|
||||||
|
beforeFns: function() { return [function(done) { }]; },
|
||||||
|
fn: function(done) { },
|
||||||
|
afterFns: function() { return [function(done) { }]; },
|
||||||
|
timer: {
|
||||||
|
setTimeout: setTimeoutSpy,
|
||||||
|
clearTimeout: function() {}
|
||||||
|
},
|
||||||
|
queueRunnerFactory: queueRunnerSpy
|
||||||
|
});
|
||||||
|
|
||||||
|
spec.execute();
|
||||||
|
var fns = queueRunnerSpy.calls.mostRecent().args[0].fns;
|
||||||
|
|
||||||
|
for (var i = 0; i < fns.length; i++) {
|
||||||
|
fns[i]();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(setTimeoutSpy.calls.count()).toEqual(3);
|
||||||
|
expect(setTimeoutSpy).toHaveBeenCalledWith(jasmine.any(Function), j$.DEFAULT_TIMEOUT_INTERVAL);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resets the timeout timer when an async before throws an exception", function() {
|
||||||
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
|
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
|
||||||
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
||||||
spec = new j$.Spec({
|
spec = new j$.Spec({
|
||||||
fn: function(done) { },
|
beforeFns: function() { return [function(done) {}]; },
|
||||||
catchExceptions: function() { return true; },
|
fn: function() { },
|
||||||
timer: {
|
timer: {
|
||||||
setTimeout: function () { return 920; },
|
setTimeout: function () { return 920; },
|
||||||
clearTimeout: clearTimeoutSpy
|
clearTimeout: clearTimeoutSpy
|
||||||
@@ -238,6 +263,44 @@ describe("Spec", function() {
|
|||||||
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
|
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("resets the timeout timer when an async spec throws an exception", function() {
|
||||||
|
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
|
||||||
|
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
||||||
|
spec = new j$.Spec({
|
||||||
|
fn: function(done) { },
|
||||||
|
timer: {
|
||||||
|
setTimeout: function () { return 920; },
|
||||||
|
clearTimeout: clearTimeoutSpy
|
||||||
|
},
|
||||||
|
queueRunnerFactory: queueRunnerSpy
|
||||||
|
});
|
||||||
|
|
||||||
|
spec.execute();
|
||||||
|
queueRunnerSpy.calls.mostRecent().args[0].fns[0]();
|
||||||
|
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
|
||||||
|
|
||||||
|
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resets the timeout timer when an async after spec throws an exception", function() {
|
||||||
|
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
|
||||||
|
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
||||||
|
spec = new j$.Spec({
|
||||||
|
fn: function() { },
|
||||||
|
afterFns: function() { return [function(done) {}]; },
|
||||||
|
timer: {
|
||||||
|
setTimeout: function () { return 920; },
|
||||||
|
clearTimeout: clearTimeoutSpy
|
||||||
|
},
|
||||||
|
queueRunnerFactory: queueRunnerSpy
|
||||||
|
});
|
||||||
|
|
||||||
|
spec.execute();
|
||||||
|
queueRunnerSpy.calls.mostRecent().args[0].fns[1]();
|
||||||
|
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
|
||||||
|
|
||||||
|
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
|
||||||
|
});
|
||||||
describe("when a spec is marked pending during execution", function() {
|
describe("when a spec is marked pending during execution", function() {
|
||||||
it("should mark the spec as pending", function() {
|
it("should mark the spec as pending", function() {
|
||||||
var fakeQueueRunner = function(opts) {
|
var fakeQueueRunner = function(opts) {
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
this.id = attrs.id;
|
this.id = attrs.id;
|
||||||
this.description = attrs.description || '';
|
this.description = attrs.description || '';
|
||||||
this.fn = attrs.fn;
|
this.fn = attrs.fn;
|
||||||
this.beforeFns = attrs.beforeFns || function() {};
|
this.beforeFns = attrs.beforeFns || function() { return []; };
|
||||||
this.afterFns = attrs.afterFns || function() {};
|
this.afterFns = attrs.afterFns || function() { return []; };
|
||||||
this.catchingExceptions = attrs.catchingExceptions;
|
|
||||||
this.onStart = attrs.onStart || function() {};
|
this.onStart = attrs.onStart || function() {};
|
||||||
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
|
||||||
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
this.getSpecName = attrs.getSpecName || function() { return ''; };
|
||||||
@@ -72,13 +71,15 @@ getJasmineRequireObj().Spec = function(j$) {
|
|||||||
timeout = void 0;
|
timeout = void 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var befores = this.beforeFns() || [],
|
var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns()),
|
||||||
afters = this.afterFns() || [],
|
allTimeoutableFns = [];
|
||||||
thisOne = (this.fn.length) ? timeoutable(this.fn) : this.fn;
|
for (var i = 0; i < allFns.length; i++) {
|
||||||
var allFns = befores.concat(thisOne).concat(afters);
|
var fn = allFns[i];
|
||||||
|
allTimeoutableFns.push(fn.length > 0 ? timeoutable(fn) : fn);
|
||||||
|
}
|
||||||
|
|
||||||
this.queueRunnerFactory({
|
this.queueRunnerFactory({
|
||||||
fns: allFns,
|
fns: allTimeoutableFns,
|
||||||
onException: onException,
|
onException: onException,
|
||||||
onComplete: complete
|
onComplete: complete
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user