Closed Bug 1707509 Opened 5 years ago Closed 5 years ago

Allow to parametrize waitFor interval & maxTries helper in a given test

Categories

(DevTools :: Console, task, P3)

task

Tracking

(firefox90 fixed)

RESOLVED FIXED
90 Branch
Tracking Status
firefox90 --- fixed

People

(Reporter: jdescottes, Assigned: jdescottes)

References

Details

Attachments

(1 file)

In Bug 1689101, we had intermittent failures because the waitFor helper was too quick to fail. The test was browser_webconsole_network_messages_expand_before_updates.js

There were a lot of waitFor calls in the file (searchfox), so to fix it we created a small wrapper:

async function waitForLonger(predicate) {
  const message = "";
  // Default interval is 10ms. The test often times out on waitFor statements
  // use a 50ms interval instead.
  const interval = 50;
  const maxTries = 500;

  return waitFor(predicate, message, interval, maxTries);
}

But this is not a great solution, and doesn't easily scale for other tests.
It would be great to either:

  • have a shared waitForLonger helper
  • have an easy way to parametrize waitFor in each test

I am leaning towards the second option. I think we could for instance drive the interval and maxTries parameters with a preference? Or a global variable? Or properties attached to the waitFor method?

Preferences could rely on the pushPref helper in order to be automatically cleanedUp on test teardown.

waitFor is currently in shared-head.js: https://searchfox.org/mozilla-central/rev/9f76a47f4aa935b49754c5608a1c8e72ee358c46/devtools/client/shared/test/shared-head.js#690-709

async function waitFor(condition, message = "", interval = 10, maxTries = 500) {
  try {
    const value = await BrowserTestUtils.waitForCondition(
      condition,
      message,
      interval,
      maxTries
    );
    return value;
  } catch (e) {
    const errorMessage =
      "Failed waitFor(): " +
      message +
      "\n" +
      "Failed condition: " +
      condition +
      "\n";
    throw new Error(errorMessage);
  }
}
Pushed by jdescottes@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3569380209f6 [devtools] Allow to parametrize waitFor helper easily for a single test r=nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 90 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: