Mattflaschen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/145479

Change subject: Fix spurious QUnit failures related to fake timers
......................................................................

Fix spurious QUnit failures related to fake timers

There were two root issues:

* jQuery uses a setInterval to run part of the effects queue.  The ID
  from this was not being cleared between modules.  Thus, even though
  setInterval itself switched to the fake timer implementation, the
  new (fake) setInterval was non-deterministically not called.

  That meant that the callback would not be called sychronously when
  Sinon's tick was called, but only later and asynchronously
  (resulting in "Expected 1 assertions, but 0 were run").

  This is fixed by calling $.fx.stop() to force jQuery to call clearInterval
  and discard its timerId.  It will call the fake setInterval when/if
  it needs to add something to the effects queue during a fake timer
  test.

* Animations could get a stale startTime (due to cached fxNow).
  Due to a large (real-time) startTime, a small duration, and a small
  (fake) currentTime:

  remaining Math.max( 0, animation.startTime + animation.duration - currentTime 
)

  would indicate a remaining animation time far in the future
  (essentially, it would never terminate).

  This is fixed by starting the fake timers at the current time when
  animation is used, so a past (cached) fxNow is still in the past.

Bug: 63579
Change-Id: Ibada489a582958f8c04d348825ce4eb49cfa59a6
---
M tests/qunit/data/testrunner.js
M tests/qunit/suites/resources/jquery/jquery.color.test.js
M tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js
3 files changed, 19 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/79/145479/1

diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js
index 50e89da..d2082b1 100644
--- a/tests/qunit/data/testrunner.js
+++ b/tests/qunit/data/testrunner.js
@@ -104,6 +104,23 @@
                                teardown: function () {
                                        this.sandbox.verifyAndRestore();
 
+                                       // Tells jQuery to clearInterval on the 
interval it uses for
+                                       // effects.
+                                       //
+                                       // This is necessary to ensure the next 
module calls the
+                                       // correct setInterval, which may be 
sinonjs's fake one,
+                                       // rather than wrongly relying on a 
stale timerId.
+                                       //
+                                       // This is done unconditionally 
(regardless of whether the
+                                       // current module uses fake timers).
+                                       //
+                                       // This means the effects queue will 
not progress
+                                       // unless/until jQuery.fx.start happens 
to be called again
+                                       // The test is being torn down, so any 
further actions in
+                                       // the effects queue will not affect 
the test results for
+                                       // this test.
+                                       $.fx.stop();
+
                                        if ( localEnv.teardown ) {
                                                localEnv.teardown.call( this );
                                        }
diff --git a/tests/qunit/suites/resources/jquery/jquery.color.test.js 
b/tests/qunit/suites/resources/jquery/jquery.color.test.js
index c8e8ac7..59a7242 100644
--- a/tests/qunit/suites/resources/jquery/jquery.color.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.color.test.js
@@ -1,7 +1,7 @@
 ( function ( $ ) {
        QUnit.module( 'jquery.color', QUnit.newMwEnvironment( {
                setup: function () {
-                       this.clock = this.sandbox.useFakeTimers();
+                       this.clock = this.sandbox.useFakeTimers( +new Date() );
                }
        } ) );
 
diff --git a/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js 
b/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js
index 8040581..a3ee51f 100644
--- a/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js
+++ b/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js
@@ -3,7 +3,7 @@
 
        QUnit.module( 'jquery.makeCollapsible', QUnit.newMwEnvironment( {
                setup: function () {
-                       this.clock = this.sandbox.useFakeTimers();
+                       this.clock = this.sandbox.useFakeTimers( +new Date() );
                }
        } ) );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/145479
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibada489a582958f8c04d348825ce4eb49cfa59a6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <mflasc...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to