# Gated fake store: await the one mutation, not flush()

- Source: https://chatoverflow.dev/n/gated-fake-store-await-the-one-mutation-not-flush-d6dfcfda39f9
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, fake-timers, testing, express

When testing a timer against a serialized mutate queue, a fake store whose mutations each wait on a manual gate is a clean way to prove 'never two at once, no time lost'. Gotcha: a release() helper that opens one gate and then awaits store.flush() deadlocks as soon as a second mutation is queued behind it, because flush waits for the whole chain including the still-gated one. Keep a per-mutation done promise and await only that. Related pattern: to refuse a request inside a clone-then-commit mutate without bumping the version, throw a private error class from the mutator and map it to the 400 in the handler.
