Yesterday, mochitest-plain-repeat jobs started running on autoland and mozilla-central. With that, every mochitest suite now has tier 1 jobs enforcing that each test passes when it runs alone in a fresh browser, and when it runs twice in a row. If you have ever tried to debug a test locally and been confused by a failure that had nothing to do with what you were investigating, this is for you.

Why this matters

When fixing a test locally. Running a single test with ./mach mochitest path/to/test.js should now work: no more hidden dependency on another test of the same manifest that happened to run first. And when trying to reproduce an intermittent failure with --repeat 10 or --run-until-failure, the second run will no longer perma-fail just because the first one left something behind. If the test fails, it's likely the failure you are looking for.

Making Test Verify reliable. Test Verify (TV) is the job that runs the tests modified by a push many times: 10 times in the same browser, 5 times with a fresh browser each time, and then all of that again in chaos mode. It's meant to catch new intermittent failures, on try before they land, and on autoland right after. Today, it fails too often for reasons that have nothing to do with the push. Nobody should be needinfo'ed because a test couldn't run alone or twice before they touched it. The standalone and repeat jobs remove 2 of these 3 sources of pre-existing failures. Chaos mode still needs work.

Getting there

Standalone jobs (Treeherder suffix sa) restart the browser before each test; use --restart-between-tests to do the same locally. Repeat jobs (suffix rp) run each test twice in a row in the same browser, like --repeat 1 (one extra run). Both run on Linux and Windows, every 20 pushes or 4 hours on autoland (on backstop pushes) and on mozilla-central.

It took many fixes, in 171 bugs, to get all the jobs green enough:

Suite Run alone Run twice
browser-chrome 44 fixes 68 fixes
devtools-chrome 8 fixes 11 fixes
chrome 4 fixes 11 fixes
plain 8 fixes 28 fixes

Only 6 tests are still skipped in standalone mode, and 6 in repeat mode.

Examples of things that broke in a fresh browser: uninitialized services, first-time flicker, hidden dependencies, window size, leaks.

Examples of things that broke on the second run: image, font and auth caches, leftover cookies, history and files, .sjs state, page zoom, once-per-session telemetry.

Fixing the browser-chrome repeat failures has been my largest stack of patches yet, and fixing all of this would not have been possible without the many engineers who reviewed them quickly. Thank you!

Actual browser bugs

Most fixes were in tests, but some were real Firefox bugs. A few examples:

  • Clearing history didn't make links unvisited. Each process caches the visited status of the links its documents track. Clearing history never reset that cache, so links in already open pages kept showing as visited.
  • A Resource Timing bug from 2014. Images served from the image cache, which is shared across documents, got no PerformanceResourceTiming entry, unlike stylesheets and scripts. The bug had collected years of "any update?" comments; a test failing when run twice finally got it fixed.
  • A crash on Windows. When the first fullscreen entry of the session came from a window opened with sizemode="fullscreen", Firefox dereferenced a renderer that didn't exist yet. Restarting the browser before each test made this crash happen every time.

Next

Chaos mode, which randomizes thread and event scheduling, is the last part of Test Verify that doesn't have its own tier 1 jobs yet. Adding randomness to scheduling will likely uncover many more bugs. Some smaller mochitest suites, like a11y and media, don't have standalone and repeat jobs yet, but they should soon.

The ongoing work to clean up flaky tests is effective, but new intermittent failures land quickly too, so the overall failure rate only goes down when we fix them faster than they get introduced. Making Test Verify tier 1 would stop most of these regressions when they land, and then we will finally have a chance of making the flakiness rate go down for good.