Bug 1582655, try to make browser_test_feature_preferencereads.js less racy and let browser_test_feature_jsallocations.js to run a bit longer, r=whawkins, a=test-only
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 24 Sep 2019 09:23:35 +0000
changeset 555308 9dd1edbf897eb02ff20660577054696489a49d94
parent 555307 cc63f94852463ec2eb9c340bdacfb908f0671a78
child 555309 c9deceeb4b59a5f0610affbfc46cb5bbe45597f4
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhawkins, test-only
bugs1582655
milestone70.0
Bug 1582655, try to make browser_test_feature_preferencereads.js less racy and let browser_test_feature_jsallocations.js to run a bit longer, r=whawkins, a=test-only Differential Revision: https://phabricator.services.mozilla.com/D46865
tools/profiler/tests/browser/browser_test_feature_jsallocations.js
tools/profiler/tests/browser/browser_test_feature_preferencereads.js
--- a/tools/profiler/tests/browser/browser_test_feature_jsallocations.js
+++ b/tools/profiler/tests/browser/browser_test_feature_jsallocations.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+requestLongerTimeout(10);
+
 /**
  * Test the JS Allocations feature. This is done as a browser test to ensure that
  * we realistically try out how the JS allocations are running. This ensures that
  * we are collecting allocations for the content process and the parent process.
  */
 add_task(async function test_profile_feature_jsallocations() {
   if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
--- a/tools/profiler/tests/browser/browser_test_feature_preferencereads.js
+++ b/tools/profiler/tests/browser/browser_test_feature_preferencereads.js
@@ -1,22 +1,41 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+requestLongerTimeout(10);
+
 function countDpiPrefReadsInThread(thread) {
   let count = 0;
   for (let payload of getPayloadsOfType(thread, "PreferenceRead")) {
     if (payload.prefName === "layout.css.dpi") {
       count++;
     }
   }
   return count;
 }
 
+async function waitForPaintAfterLoad() {
+  return ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
+    return new Promise(function(resolve) {
+      function listener() {
+        if (content.document.readyState == "complete") {
+          content.requestAnimationFrame(() => setTimeout(resolve, 0));
+        }
+      }
+      if (content.document.readyState != "complete") {
+        content.document.addEventListener("readystatechange", listener);
+      } else {
+        listener();
+      }
+    });
+  });
+}
+
 /**
  * Test the PreferenceRead feature.
  */
 add_task(async function test_profile_feature_preferencereads() {
   if (!AppConstants.MOZ_GECKO_PROFILER) {
     return;
   }
   Assert.ok(
@@ -29,18 +48,17 @@ add_task(async function test_profile_fea
   const url = BASE_URL + "fixed_height.html";
   await BrowserTestUtils.withNewTab(url, async contentBrowser => {
     const contentPid = await ContentTask.spawn(
       contentBrowser,
       null,
       () => Services.appinfo.processID
     );
 
-    // Wait 100ms so that the tab finishes executing.
-    await wait(100);
+    await waitForPaintAfterLoad();
 
     // Check that some PreferenceRead profile markers were generated when the
     // feature is enabled.
     {
       const { contentThread } = await stopProfilerAndGetThreads(contentPid);
 
       const timesReadDpiInContent = countDpiPrefReadsInThread(contentThread);
 
@@ -49,18 +67,27 @@ add_task(async function test_profile_fea
         0,
         "PreferenceRead profile markers for layout.css.dpi were recorded " +
           "when the PreferenceRead feature was turned on."
       );
     }
 
     startProfiler({ features: ["threads"] });
     // Now reload the tab with a clean run.
-    gBrowser.reload();
-    await wait(100);
+    await ContentTask.spawn(contentBrowser, null, () => {
+      return new Promise(resolve => {
+        addEventListener("pageshow", () => resolve(), {
+          capturing: true,
+          once: true,
+        });
+        content.location.reload();
+      });
+    });
+
+    await waitForPaintAfterLoad();
 
     // Check that no PreferenceRead markers were recorded when the feature
     // is turned off.
     {
       const { parentThread, contentThread } = await stopProfilerAndGetThreads(
         contentPid
       );
       Assert.equal(