From 55149310c374ee7fa492c3bba23811abe20539b7 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Wed, 25 Aug 2010 17:16:19 -0700 Subject: [PATCH] Fixed bug: waitsFor() hangs forever if latch function never returns true. --- spec/suites/SpecRunningSpec.js | 2 +- spec/suites/WaitsForBlockSpec.js | 2 +- src/Queue.js | 7 ++++++- src/WaitsForBlock.js | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index e837c2a..9f5d725 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -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); }); }); diff --git a/spec/suites/WaitsForBlockSpec.js b/spec/suites/WaitsForBlockSpec.js index ea58833..6927194 100644 --- a/spec/suites/WaitsForBlockSpec.js +++ b/spec/suites/WaitsForBlockSpec.js @@ -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(); }); }); }); \ No newline at end of file diff --git a/src/Queue.js b/src/Queue.js index c3e064a..065408c 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -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) { @@ -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; @@ -48,6 +49,10 @@ jasmine.Queue.prototype.next_ = function() { return; } + if (self.blocks[self.index].abort) { + self.abort = true; + } + self.offset = 0; self.index++; diff --git a/src/WaitsForBlock.js b/src/WaitsForBlock.js index 676e005..b413b38 100644 --- a/src/WaitsForBlock.js +++ b/src/WaitsForBlock.js @@ -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;