DEV Community

CodeOps
CodeOps

Posted on

Stop Guessing Whether a Test Is Flaky — Measure Its Failure Rate

Every team has one: the test everyone re-runs "just in case". Someone says it's flaky. Someone else says it caught a real bug once. Nobody actually knows its failure rate — so the argument never ends, and the re-runs never stop.

Retries make this worse, not better. A retry hides the failure, so the flake never gets counted, so it never gets fixed. Dashboards average the signal away. What you need before any fix is a number you can defend: this test failed K of N runs on a real CI runner.

The measurement, as a free Action

I published Flake Scan, a free GitHub Action that does exactly this one job: it runs a single suspect test command N times on a real runner and reports the measured failure rate — per-run table included — in the workflow's job summary.

- uses: codeopscontact/flake-scan-action@v1
  with:
    command: "npx jest path/to/flaky.test.ts -t 'checkout totals'"
    iterations: "50"
Enter fullscreen mode Exit fullscreen mode

That's the whole interface. command is the test to repeat (a single test is best), iterations defaults to 20, and there's a working-directory input if your tests don't live at the repo root. Python works the same way — swap in a pytest command. It's on the GitHub Marketplace: search "Flake Scan", or find it at github.com/marketplace/actions/flake-scan-measure-a-test-s-real-failure-rate.

Run it manually when a test smells flaky, or on a weekly schedule so a creeping failure rate shows up before it becomes the team's folklore.

How to read the number

  • 0 failures in N runs — the rate is below 1/N under these conditions. That doesn't clear the test; widen the iterations or reproduce under load before closing the issue.
  • Low rate (≤10%) — usually yields to controlled reproduction: seed control, test isolation, parallel-load control. Not retries.
  • High rate (>10%) — reproduction is cheap, which is good news: bisect recent changes and hunt shared state first.

The point of the number is that it ends the opinion phase. "Failed 7 of 50 runs (14%) on CI hardware, here is the table" is a statement a team can act on. "It fails sometimes" is not.

After the measurement

Measuring is step one. The full method — classifying a flake into one of five root-cause classes, fixing per class, and the quarantine policy that keeps flakes from creeping back — is the Flaky CI Rescue Kit ($49):

And if you'd rather hand the whole problem over: CodeOps runs fixed-price CI repair sprints (flaky tests, CI cost, Actions security), prepaid or escrowed, scoped before work starts — https://contra.com/codeopscontact

The Action is MIT-licensed and free forever. Measure first. Then fix the cause, not the symptom.

Top comments (0)