Fix intermittent QUnit failure
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 14 Nov 2012 22:51:06 +0000 (14:51 -0800)
committerTimo Tijhof <ttijhof@wikimedia.org>
Wed, 14 Nov 2012 23:09:59 +0000 (00:09 +0100)
Occasionally the test 'mediawiki: mw.loader.implement( styles={ "url": {
<media>: [url, ..] } } )' will fail because it only ran 5 of 7 expected
assertions, while at the same time a later test will fail because it had
two extra assertions.

The problem is that the test is performing two external CSS loads, but
calls QUnit.start() after the ''first'' one is loaded. If the second
doesn't manage to get loaded at close to the same time, QUnit moves on
to the next test, and then when the second external CSS file finally
does load it will get counted towards whichever test is running at that
time. This can be reliably reproduced by arranging for
tests/qunit/data/styleTest.css.php to take longer for one than the other
of these two external CSS loads.

The solution is to wait until *both* of those external CSS loads to
complete (or time out) before calling QUnit.start().

Change-Id: Id695e95733b4c3f58234d9688c6b6e1b9ba591cc

tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index 9286558..dc7bd0a 100644 (file)
@@ -277,15 +277,25 @@ QUnit.asyncTest( 'mw.loader.implement( styles={ "url": { <media>: [url, ..] } }
        mw.loader.implement(
                'test.implement.b',
                function () {
+                       // Note: QUnit.start() must only be called when the entire test is
+                       // complete. So, make sure that we don't start until *both*
+                       // assertStyleAsync calls have completed.
+                       var pending = 2;
                        assertStyleAsync( assert, $element2, 'float', 'left', function () {
                                assert.notEqual( $element1.css( 'text-align' ), 'center', 'print style is not applied' );
 
-                               QUnit.start();
+                               pending--;
+                               if ( pending === 0 ) {
+                                       QUnit.start();
+                               }
                        } );
                        assertStyleAsync( assert, $element3, 'float', 'right', function () {
                                assert.notEqual( $element1.css( 'text-align' ), 'center', 'print style is not applied' );
 
-                               QUnit.start();
+                               pending--;
+                               if ( pending === 0 ) {
+                                       QUnit.start();
+                               }
                        } );
                },
                {