Bug 1378577: Fix await race condition which causes intermittent timeouts in test_stylesheet_clone_import_rule.html. r=emilio
authorBrad Werth <bwerth@mozilla.com>
Mon, 28 Aug 2017 17:02:06 -0700
changeset 377351 7f2bcb7a902df52772f150f15de8003ff30bbc80
parent 377350 1bdcee585e107c3a34533b9682d604b39f960bce
child 377352 389bbf5ac7bbb67060dc4b2e447b615f2ce59420
push id32407
push userarchaeopteryx@coole-files.de
push dateTue, 29 Aug 2017 18:28:36 +0000
treeherdermozilla-central@d814f791de3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1378577
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1378577: Fix await race condition which causes intermittent timeouts in test_stylesheet_clone_import_rule.html. r=emilio MozReview-Commit-ID: 2vWsCcnsmwF
layout/style/test/chrome/test_stylesheet_clone_import_rule.html
--- a/layout/style/test/chrome/test_stylesheet_clone_import_rule.html
+++ b/layout/style/test/chrome/test_stylesheet_clone_import_rule.html
@@ -28,22 +28,32 @@
     return Array.from(cssRules).map(rule => rule.cssText).join('');
   }
 
   async function runTest() {
 
     // Test that the div is initially red (from base.css)
     is(getComputedStyle(theOnlyDiv).color, "rgb(0, 128, 0)", "div begins as green.");
 
+    // Create a Promise to watch for some number of events.
+    let generateCountingListenerCallback = function(numberOfEventsToWaitFor) {
+      let eventsReceived = 0;
+      return function(event) {
+        return (++eventsReceived >= numberOfEventsToWaitFor);
+      }
+    };
+    let gotAllOurStyleRuleAddedEvents = ContentTaskUtils.waitForEvent(document,
+      "StyleRuleAdded", true, generateCountingListenerCallback(2));
+
     stylesheet.insertRule('@import url("import_useless2.css")', 0);
     stylesheet.insertRule('@import url("import_useless2.css")', 1);
 
-    // Wait for two StyleRuleAdded events to be fired.
-    await ContentTaskUtils.waitForEvent(document, "StyleRuleAdded", true);
-    await ContentTaskUtils.waitForEvent(document, "StyleRuleAdded", true);
+    // Wait for the StyleRuleAdded events to be fired. This function returns the last event,
+    // but we don't care what it contains -- only that the correct number of events fired.
+    await gotAllOurStyleRuleAddedEvents;
 
     // Get the imported sheets and confirm they are non-null and have rules.
     let importSheet1 = stylesheet.cssRules[0].styleSheet;
     let importSheet2 = stylesheet.cssRules[1].styleSheet;
 
     ok(importSheet1 && importSheet2, "Imported sheets exist.");
     if (!(importSheet1 && importSheet2)) {
       SimpleTest.finish();