Back to the journal

Your flaky test suite is training the team to ignore red builds

There is a specific moment that kills a test suite, and it is not when a test breaks. It is when someone says "just re-run it" and everyone nods. Once a failing build becomes something you retry rather than investigate, your CI pipeline has stopped being a signal and become a slot machine. The tests are still green most of the time, the badge still says passing, and the whole thing is now theatre. We have watched this happen on more than one project, including our own, and the frustrating part is that it rarely arrives through one catastrophic bad test. It accumulates one tolerated flake at a time until a red build means nothing at all.

How a suite learns to lie

A flaky test is one that passes and fails without any change to the code under test. The first one usually seems harmless. A test that hits the real clock fails once at midnight because of a date rollover, someone re-runs the job, it passes, and the pull request merges. Nobody files a ticket because nothing is actually broken in the product. The cost is invisible on that day. What you have actually done is teach the team a small lesson: a red build is sometimes a lie, and the correct response to a red build is to try again.

The damage is that this lesson generalises. Six months later there are fifteen tests that fail intermittently, and the team has fully internalised the retry reflex. Now a genuine regression lands, the build goes red, and the author shrugs and clicks re-run because that is what you do here. It passes on the third attempt because the real bug is also intermittent, or because the broken test happened to be masked by a flaky neighbour. The suite caught the bug and the humans overrode it. You did not have a testing problem at that point, you had a trust problem, and trust is the entire product a test suite sells.

The insidious bit is that flakiness is contagious across a team's attention. Once people stop reading failure output carefully, they stop noticing the one failure that matters among the three that don't. A suite with even a five percent flake rate per run effectively has no stopping power on a busy repo, because almost every run has at least one unrelated failure to blame.

The usual sources, and how to tell them apart

Most flakes come from a short list of causes, and naming the cause tells you the fix. Time and timezones are the classic: a test that constructs a date, asserts on "tomorrow", and breaks when CI runs in UTC while you develop in SAST. Order dependence is next, where test A leaves a row in the database or a value in a module-level cache and test B only passes if A ran first. Run your suite in a randomised order once and watch how many failures appear, because a suite that depends on order is lying about what each test proves.

Concurrency and shared state are the hardest. Two tests touching the same fixture record, a parallel test runner with a shared Redis instance, a port that is occasionally still held by the previous test, an async operation that is asserted on before it settles. These produce failures that correlate with load, so they show up more on a loaded CI runner than on your quiet laptop, which is exactly why "works on my machine" is such a common and useless observation here. The network is the fourth bucket: any test that reaches a real external service is flaky by definition, because that service has its own availability and latency, and you have imported it into your pass rate.

To tell them apart, instrument before you guess. Record every test failure with its full output, the seed used for ordering, the git SHA, and the runner identity, into a table you can query. After a week you can ask which tests failed on commits that also passed on re-run with no code change. That query is your flake list, produced from evidence rather than from the one test everybody already complains about.

Quarantine is a feature, not an admission of defeat

The instinct when you find a flaky test is to either fix it immediately or delete it. Both are usually wrong in the moment. Fixing it immediately blocks the author who just wants to merge an unrelated change, and deleting it throws away whatever real coverage it provided. The better move is an explicit quarantine: tag the test so it still runs and still reports, but its result no longer fails the build. Most runners support this through markers or a separate job. The crucial discipline is that quarantine is a tracked, time-boxed state with a ticket attached, not a graveyard where tests go to be forgotten.

Quarantine works because it restores the one property that matters: when the main build is red, it is genuinely red, and the team can trust it again immediately. You have separated the signal you rely on from the tests you are repairing. We put a hard cap on it, something like no more than ten tests in quarantine at once and nothing quarantined longer than two weeks, which forces the team to either fix the test or consciously decide the coverage is not worth keeping. Without that cap, quarantine becomes a way to make the pipeline green by hiding everything inconvenient, which is the same disease in a nicer outfit.

The common mistake is treating a quarantined test as lower priority forever. In practice a flaky test is often pointing at a flaky part of the actual system, a race condition or a timeout that real users will hit, so the test deserves attention precisely because it is hard to make pass deterministically. The test is doing its job by being annoying.

The takeaway

On Monday, do this in order. Run your full suite three times in a row on CI without changing any code and write down which tests failed at least once, because those are your confirmed flakes and you should not argue about them. Add logging that captures every failure with its SHA, ordering seed and runner identity into somewhere queryable, so next time you are working from data instead of memory. Introduce a quarantine mechanism this week, a marker that keeps a test running and reporting but stops it failing the build, and put a visible cap on how many tests may sit there and for how long. Run your suite in randomised order at least once to surface order dependence, and fix any test that reaches a real external service by replacing that call with a fake or a recorded response. Most importantly, change the social rule: a red build gets investigated before it gets re-run, and "just re-run it" is the thing you call out in review, not the thing you reach for. The goal is simple and worth protecting fiercely. When the build is red, everyone should believe it.

A note on the people, not just the tooling

None of this holds without the team agreeing that a red build is information rather than an obstacle. The tooling makes the behaviour possible; the agreement makes it stick. If one senior person keeps re-running without investigating, everyone copies them, and your quarantine system becomes paperwork around the same old shrug.

FROM IDEAS TO SOMETHING REAL

Your next chapter.
Let’s build it.

A website, an app, a better way to work. Tell us what you have in mind.

Start a conversation