Make the ordering part of the test
An intermittent stale-response bug often disappears during debugging because timing changes. A deterministic test should specify which request starts first, which response returns first and which user action occurs between them. This can run entirely against a local fixture transport.
What to do next
- 01
Name the competing events
Identify the two network observations or writes that conflict, plus the user action whose result must be protected. Record their intended causal order before adding test delays or mocking helpers.
- 02
Hold one event at a barrier
Intercept a chosen request and keep its response pending. Allow the competing response or user selection to complete, then release the held response using an explicit test signal rather than an arbitrary timeout.
- 03
Assert durable and visible outcomes
Check both the displayed result and the underlying saved revision or selection. Repeat after navigation or reload so a correct temporary view cannot hide an incorrect persisted write.
A concrete example
Illustrative example: the test holds quote A, edits the size, lets quote B render and then releases A. The displayed estimate and approved revision must still belong to B, including after the project is reloaded.
Before you call it ready
- Tests control order without long sleeps.
- Assertions cover persisted state.
- The losing response is actually released.
When to stop or choose another method
Stop calling an intermittent race fixed solely because a stress test happened to pass; encode the harmful event order explicitly.
