Why are tests flaky and how do you fix them?
The gist
A flaky test passes and fails on the same code. It is worse than no test at all: the team gets used to rerunning CI, and a real regression drowns in "it blinked again". The cause is almost always the same — the test depends on something it does not control: run order, real time, the thread scheduler, the network or state left behind by a neighbour. Fix that dependency, not the timeout.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep