Bug 1576472 - Fix browser_about_debugging_link.js intermittent failure due to RDP requests pending while closing the tab. r=jdescottes

browser_about_debugging_link.js is testing the page options that open (or switch) to about:debugging
from about:addons.

This test seems to be failing intermittently because there are pending RDP requests when the about:debugging
tab is being closed once the test is completed.

We already had a similar issue before and at the time daisuke provided us the test helpers currently used
in the test to wait for the tabs, workers and extensions to be populated in the store.

Unfortunately this doesn't seem enough anymore, especially with fission enabled the test is keep
failing because it seems that some new RDP requests are pending when we are closing the tab
(from the stacktrace it seems that the pending requests are triggered by the "processes updates listener").

The waitForRequestsToSettle test helper used in some other about:debugging tests seems to be able to fix
the intermittent failure (trying on linux64 debug locally it passed test-verify multiple times).

Differential Revision: https://phabricator.services.mozilla.com/D49015

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2019-10-14 13:16:29 +00:00
parent cbc7251ad9
commit b3de1edab5

View File

@ -22,6 +22,43 @@ function waitForDispatch(store, type) {
});
}
/**
* Wait for all client requests to settle, meaning here that no new request has been
* dispatched after the provided delay. (NOTE: same test helper used in about:debugging tests)
*/
async function waitForRequestsToSettle(store, delay = 500) {
let hasSettled = false;
// After each iteration of this while loop, we check is the timerPromise had the time
// to resolve or if we captured a REQUEST_*_SUCCESS action before.
while (!hasSettled) {
let timer;
// This timer will be executed only if no REQUEST_*_SUCCESS action is dispatched
// during the delay. We consider that when no request are received for some time, it
// means there are no ongoing requests anymore.
const timerPromise = new Promise(resolve => {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
timer = setTimeout(() => {
hasSettled = true;
resolve();
}, delay);
});
// Wait either for a REQUEST_*_SUCCESS to be dispatched, or for the timer to resolve.
await Promise.race([
waitForDispatch(store, "REQUEST_EXTENSIONS_SUCCESS"),
waitForDispatch(store, "REQUEST_TABS_SUCCESS"),
waitForDispatch(store, "REQUEST_WORKERS_SUCCESS"),
timerPromise,
]);
// Clear the timer to avoid setting hasSettled to true accidently unless timerPromise
// was the first to resolve.
clearTimeout(timer);
}
}
function waitForRequestsSuccess(store) {
return Promise.all([
waitForDispatch(store, "REQUEST_EXTENSIONS_SUCCESS"),
@ -48,7 +85,6 @@ add_task(async function testAboutDebugging() {
debugAddonsBtn.doCommand();
await loaded;
let aboutDebuggingTab = gBrowser.selectedTab;
const { AboutDebugging } = aboutDebuggingTab.linkedBrowser.contentWindow;
// Avoid test failures due to closing the about:debugging tab
// while it is still initializing.
@ -66,6 +102,11 @@ add_task(async function testAboutDebugging() {
debugAddonsBtn.doCommand();
await switched;
info("Wait until any new about:debugging request did settle");
// Avoid test failures due to closing the about:debugging tab
// while it is still initializing.
await waitForRequestsToSettle(AboutDebugging.store);
info("Remove the about:debugging tab");
BrowserTestUtils.removeTab(aboutDebuggingTab);