Skip to content

Commit

Permalink
Fixed bug: waitsFor() hangs forever if latch function never returns t…
Browse files Browse the repository at this point in the history
…rue.
  • Loading branch information
xian committed Aug 26, 2010
1 parent 254ebb8 commit 5514931
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spec/suites/SpecRunningSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ describe("jasmine spec running", function () {
fakeTimer.tick(400);
expect(runsBlockExecuted).toEqual(false);
expect(timeoutSpec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for something to happen');
// todo: expect(subsequentSpecRan).toEqual(true); [xw 20100819]
expect(subsequentSpecRan).toEqual(true);
});
});

Expand Down
2 changes: 1 addition & 1 deletion spec/suites/WaitsForBlockSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('WaitsForBlock', function () {
expect(spec.fail).toHaveBeenCalled();
var failMessage = spec.fail.mostRecentCall.args[0].message;
expect(failMessage).toMatch(message);
expect(onComplete).not.toHaveBeenCalled(); // todo: this is an issue... [xw 20100819]
expect(onComplete).toHaveBeenCalled();
});
});
});
7 changes: 6 additions & 1 deletion src/Queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jasmine.Queue = function(env) {
this.running = false;
this.index = 0;
this.offset = 0;
this.abort = false;
};

jasmine.Queue.prototype.addBefore = function(block) {
Expand Down Expand Up @@ -38,7 +39,7 @@ jasmine.Queue.prototype.next_ = function() {
while (goAgain) {
goAgain = false;

if (self.index < self.blocks.length) {
if (self.index < self.blocks.length && !this.abort) {
var calledSynchronously = true;
var completedSynchronously = false;

Expand All @@ -48,6 +49,10 @@ jasmine.Queue.prototype.next_ = function() {
return;
}

if (self.blocks[self.index].abort) {
self.abort = true;
}

self.offset = 0;
self.index++;

Expand Down
4 changes: 3 additions & 1 deletion src/WaitsForBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
name: 'timeout',
message: message
});
// todo: need to prevent additional blocks in this spec from running... [xw 20100819]

this.abort = true;
onComplete();
} else {
this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
var self = this;
Expand Down

0 comments on commit 5514931

Please sign in to comment.