FUNDAMENTALS · 7 MIN READ

What Is a Flaky Test? Causes, Impact, and How to Eliminate Test Flakiness

Learn what a flaky test is, why flaky tests break CI velocity, how to measure test flakiness, and how FlakeCheck quarantines unstable tests.

Definition of a Flaky Test

A flaky test is an automated test that both passes and fails across repeated executions against the exact same source code and commit SHA. Because no application code changed between the failing run and the passing rerun, a flaky test breaks the fundamental contract of continuous integration: a red build should always mean a real defect.

In modern engineering organizations, test flakiness is rarely caused by a single bad assertion. It emerges from non-determinism in timing, asynchronous event loops, shared database fixtures, network calls to external sandboxes, CPU contention on CI runners, or subtle OS and timezone differences between developer laptops and Linux containers.

Teams often search for a reliable flaky test detector — whether they call it FlakeCheck, Flake Check, or flake-check — once engineers begin habitually clicking "Re-run failed jobs" in GitHub Actions or GitLab CI. The moment developers stop trusting red builds, genuine regressions slip into production alongside retries.

The Hidden Engineering Cost of Flaky Tests in CI

Every unnecessary CI rerun consumes runner minutes, blocks merge queues, and forces context switches. Suppose a 15-minute CI pipeline has just a 5% per-run flake probability across 40 pull requests per day. That translates to dozens of broken builds every week, hours of wasted compute, and lost developer focus.

Measuring this cost objectively is the fastest way to prioritize reliability work. FlakeCheck calculates exact CI runner time wasted on flaky reruns and converts it into a transparent monthly USD figure per repository and team.

# Ingest JUnit, CTRF, Jest, Vitest, Playwright, Pytest, Mocha, or Go test reports
npx @onurdrsn/flakecheck ingest ./junit.xml --format junit
npx @onurdrsn/flakecheck report --format markdown

Six Primary Root Causes of Test Flakiness

1. Timing and race conditions: hard-coded sleeps, unawaited promises, animations, or DOM elements detaching before Playwright or Cypress interacts with them.

2. Test order dependency: tests that pass only when executed after another test populates global state, mocks, or module singletons, and fail when run in isolation or randomized order.

3. Network and external services: tests hitting live third-party APIs or shared staging endpoints that occasionally return HTTP 429, 502, 503, ECONNRESET, or DNS timeouts.

4. Shared state collisions: parallel workers fighting over hardcoded TCP ports (EADDRINUSE), shared database rows (unique constraint violations), or temp files.

5. Resource and concurrency exhaustion: CI runners hitting OOM (exit code 137 / SIGKILL), file descriptor limits (EMFILE), or connection pool exhaustion under high worker counts.

6. Environment differences: tests passing on macOS with local timezones while failing on UTC Linux CI containers due to locale formatting, path separators, or clock skew.

How Statistical Flaky Test Detection Works

Simple retry counters produce noisy false positives when a real regression is retried or when a single infrastructure outage hits a runner. Production-grade flaky test detection combines two signals: same-commit rerun flips (definitive proof of non-determinism) and historical cross-run flip rates smoothed with a Wilson score confidence interval and a minimum sample size guard.

Once a test crosses your configured flakiness score threshold (for example 60/100 across at least 5 samples), FlakeCheck automatically classifies its root cause, quarantines it in non-blocking mode so PRs keep shipping, and opens a tracked issue in GitHub Issues, Jira, or Linear with concrete remediation steps.

Frequently Asked Questions

How many flaky tests is too many for a CI suite?

If more than 1% of CI builds fail due to non-deterministic tests, developer trust erodes rapidly. Tracking health score and quarantining tests with a flakiness score above 60 keeps merge queues green while owners fix root causes.

Should we delete flaky tests or quarantine them?

Never silently delete coverage. Quarantine flaky tests in non-blocking mode with an assigned owner and an auto-graduation policy (such as 10 consecutive clean passes) so they return to blocking CI once fixed.

Eliminate flaky tests automatically with FlakeCheck

Stream your JUnit, CTRF, Jest, Vitest, Playwright, Pytest, Mocha, or Go reports to FlakeCheck and get statistical scoring + auto-quarantine in minutes.

Related Guides