A Deterministic Test for Concurrent Database Behavior
A useful concurrency test coordinates workers at known points instead of assuming their operations overlap based on timing alone.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a planned conflict
Two ordinary test sessions can both read version four, then wait until one transaction commits its update. Let the other attempt its stale update afterward. Version-checked writes provide a visible expected outcome.
Check the actual engine
A lightweight test database can have different locking behavior from production. Exercise the promised concurrency use on the supported database. Integration tests apply at that storage boundary.[1]
Force the ordering you are trying to prove
A test can open two independent database connections. Let both observe an initial version, then permit A to change it before B tries a guarded edit. Synchronization primitives make the intended order repeatable without fixed delays. See conditional version updates.
Connections A and B read version 4
Barrier confirms both reads
A commits version 5
B attempts old-version update → expected zero rows
Query durable state after both operations finish
A single test transaction may conceal the actual connection boundary. Check final state in an independent transaction and include a timeout so a blocked test fails intelligibly.