The suite fails about one run in ten and passes on retry, how do teams actually deal with flaky tests?
Roughly one in ten pipeline runs fails. Press retry and it goes green. Nobody has ever found a real bug behind one of these failures.
The practical result is that a red build no longer means anything. People retry first and look second, and last month a genuine failure sat for two days because everyone assumed it was the usual.
We have talked about adding automatic retries so it stops interrupting people, and something about that feels wrong to me even though it would solve the immediate annoyance.
What do teams that have got on top of this actually do? I do not know where to start when the failures move around and I cannot reproduce them locally.
@shared_state_sena · 3w ago
For actually finding the cause, the categories are few and you can usually identify which one you have quickly.
Shared state between tests. The most common by a distance. A database row, a file, an environment variable, a module-level cache, a clock somebody stubbed and did not restore. Symptom: the test passes alone and fails in the suite, or fails only in a particular order.
Test order dependence. Related, and easy to prove - run the suite with randomised order locally. If failures appear, you have it. A lot of test runners can do this with a flag and it is the single most productive ten minutes here.
Real timing and waiting. Sleeps instead of waiting for a condition, and anything asserting on something that has not happened yet. Symptom: fails more on slow or loaded machines, which is why it fails in CI and not on your laptop.
Real dependencies. A test hitting the network or a live service. Intermittent by nature.
Resource limits. CI runners are usually smaller than a developer machine, so memory or parallelism issues show up only there.
The reason you cannot reproduce locally is nearly always the last two, your laptop is faster and less contended. Try running the suite with reduced parallelism on a loaded machine and a fair number will suddenly be reproducible.
Reply
Report