Bug 1518410, try to make browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js fail a bit less likely, r=Ehsan, a=test-only
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 19 Sep 2019 14:29:09 +0000
changeset 555303 b903d1db9c3437f16021c1fca5e61c4127b79a38
parent 555302 d12a3157212a37629fe31e1b272445110c9b5660
child 555304 d02ca673ea9e10bd7e09c76aefe0e84f0fbbced5
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)
reviewersEhsan, test-only
bugs1518410, 1579591
milestone70.0
Bug 1518410, try to make browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js fail a bit less likely, r=Ehsan, a=test-only There is still another related bug 1579591, which this may make a bit less likely, since that seems to be timing dependent, but the patch is not trying to fix that. Differential Revision: https://phabricator.services.mozilla.com/D46242
browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js
--- a/browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js
@@ -48,38 +48,42 @@ add_task(async function test_uniqueDomai
 
   await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "http://127.0.0.1");
   is(
     URICountListener.uniqueDomainsVisitedInPast24Hours,
     startingCount + 1,
     "127.0.0.1 should not count as a unique visit"
   );
 
-  // Set the expiry time to 1 second
+  // Set the expiry time to 4 seconds. The value should be reasonably short
+  // for testing, but long enough so that waiting for openNewForegroundTab
+  // does not cause the expiry timeout to run.
   await SpecialPowers.pushPrefEnv({
-    set: [["browser.engagement.recent_visited_origins.expiry", 1]],
+    set: [["browser.engagement.recent_visited_origins.expiry", 4]],
   });
 
   // http://www.exämple.test
   await BrowserTestUtils.openNewForegroundTab(
     win.gBrowser,
     "http://xn--exmple-cua.test"
   );
   is(
     URICountListener.uniqueDomainsVisitedInPast24Hours,
     startingCount + 2,
     "www.exämple.test should count as a unique visit"
   );
 
   let countBefore = URICountListener.uniqueDomainsVisitedInPast24Hours;
 
-  await new Promise(resolve => {
-    setTimeout(_ => {
-      let countAfter = URICountListener.uniqueDomainsVisitedInPast24Hours;
-      is(countAfter, countBefore - 1, "The expiry should work correctly");
-      resolve();
-    }, 1100);
-  });
+  // If expiration does not work correctly, the following will time out.
+  await BrowserTestUtils.waitForCondition(() => {
+    return (
+      URICountListener.uniqueDomainsVisitedInPast24Hours == countBefore - 1
+    );
+  }, 250);
+
+  let countAfter = URICountListener.uniqueDomainsVisitedInPast24Hours;
+  is(countAfter, countBefore - 1, "The expiry should work correctly");
 
   BrowserTestUtils.removeTab(win.gBrowser.selectedTab);
   BrowserTestUtils.removeTab(win.gBrowser.selectedTab);
   await BrowserTestUtils.closeWindow(win);
 });