From f9462fc7026dc691aa8f074d5604e31f8c760908 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 14 Nov 2012 14:51:06 -0800 Subject: [PATCH] Fix intermittent QUnit failure Occasionally the test 'mediawiki: mw.loader.implement( styles={ "url": { : [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 --- .../suites/resources/mediawiki/mediawiki.test.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js index 9286558127..dc7bd0a6a4 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.test.js @@ -277,15 +277,25 @@ QUnit.asyncTest( 'mw.loader.implement( styles={ "url": { : [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(); + } } ); }, { -- 2.20.1