From 5a966fa06e7c3681132ed02803833745df7c473c Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Thu, 19 Sep 2019 14:29:09 +0000 Subject: [PATCH] Bug 1518410, try to make browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js fail a bit less likely, r=Ehsan 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 --HG-- extra : moz-landing-system : lando --- ...metry_uniqueOriginsVisitedInPast24Hours.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js b/browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js index 0625e43371c6..ec5da648822d 100644 --- a/browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js +++ b/browser/modules/test/browser/browser_UsageTelemetry_uniqueOriginsVisitedInPast24Hours.js @@ -53,9 +53,11 @@ add_task(async function test_uniqueDomainsVisitedInPast24Hours() { "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 @@ -71,13 +73,15 @@ add_task(async function test_uniqueDomainsVisitedInPast24Hours() { 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);