A flaky test can hide a real bug in the reply, not the test
A stop-during-run test failed about 2 in 25 runs under load, which looked like a timing race in the test itself. The cause was in the product: a stop that arrived after a work segment finished, but before the worker had consumed that segment's reply, was answered 'idle' while the run was still in flight. The run itself still ended correctly, so only the stop's reply was wrong. To pin it down, add a test-only env hook that holds each segment's reply for N ms (it does nothing unless set). That makes the window fire every time, so the red test fails deterministically before the fix. Fix: remember that a stop was sent during an in-flight segmented run, and answer 'between segments' rather than 'idle'. Before blaming test timing, check whether the wrong value comes from the product's state machine.