From d83c901a07bd09cb9c583a57a0b4cd431bf71f8f Mon Sep 17 00:00:00 2001 From: Assaf Arkin Date: Thu, 27 Nov 2014 13:08:44 -0800 Subject: [PATCH] FIXED eliminated endless spinning of the event loop --- CHANGELOG.md | 8 ++++++++ src/zombie/eventloop.coffee | 10 ++++------ test/history_test.js | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 841addbb0..8ad45684b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## Version 2.3.3 2014-11-27 + +FIXED eliminated endless spinning of the event loop + + 695 passing (10s) + 8 pending + + ## Version 2.3.2 2014-11-26 FIXED XHR status and response text in case of error #811 diff --git a/src/zombie/eventloop.coffee b/src/zombie/eventloop.coffee index 41e51ede6..c7921a481 100644 --- a/src/zombie/eventloop.coffee +++ b/src/zombie/eventloop.coffee @@ -79,7 +79,7 @@ class EventLoop extends EventEmitter wait: (waitDuration, completionFunction)-> # Don't wait longer than duration waitDuration = ms(waitDuration.toString()) || @browser.waitDuration - timeout = Date.now() + waitDuration + timeoutOn = Date.now() + waitDuration # Someone (us) just started paying attention, start processing events ++@waiting @@ -97,7 +97,7 @@ class EventLoop extends EventEmitter timer = global.setTimeout(resolve, waitDuration) ontick = (next)=> - if next >= timeout + if next >= timeoutOn # Next event too long in the future, or no events in queue # (Infinity), no point in waiting resolve() @@ -223,10 +223,8 @@ class EventLoop extends EventEmitter @emit("tick", 0) else # All that's left are timers - time = @active._eventQueue.next() - @emit("tick", time) - #setTimeout @run.bind(this), time - Date.now() - @run() + nextTick = @active._eventQueue.next() + @emit("tick", nextTick) catch error @emit("error", error) return diff --git a/test/history_test.js b/test/history_test.js index c2b2d7f1a..d92142b8c 100644 --- a/test/history_test.js +++ b/test/history_test.js @@ -347,10 +347,13 @@ describe('History', function() { describe('change hash', function() { before(()=> browser.visit('/')); + before(function(done) { browser.document.body.innerHTML = 'Wolf'; browser.window.addEventListener('hashchange', ()=> done()); browser.window.location.hash = 'boo'; + // Get the event loop running + browser.wait(); }); it('should add page to history', function() {