Deterministic scheduling for tests¶
Category: Testing and tools · Status: stub · Lessons: chapter 09, Testing and tools (planned)
One line: Running concurrent code under a controlled scheduler or a fake clock, so that an interleaving or a timeout can be reproduced on demand — Rust's loom, Go's testing/synctest.
Also called: loom, synctest, deterministic simulation, virtual time.
How it connects¶
flowchart LR
n_deterministic_testing["Deterministic scheduling for tests"]
n_heisenbug["Heisenbug"]
n_deterministic_testing -->|prevents| n_heisenbug
classDef center stroke-width:3px
class n_deterministic_testing center
classDef outside stroke-dasharray: 4 3
class n_heisenbug outside
- Helps prevent: Heisenbug
- See also: Heisenbug, Model checking
In each language¶
| Rust | loom ↗ runs a test many times, permuting the possible concurrent executions of it |
| Go | testing/synctest ↗, new in Go 1.25 ↗: a bubble with a fake clock, and Wait until every other goroutine in it is durably blocked |
| C# | Microsoft's Coyote ↗ writes concurrency unit tests that control a .NET program's non-determinism |
| Kotlin | runTest ↗ in kotlinx-coroutines-test skips delays using the virtual time of a TestCoroutineScheduler |
Where to read more¶
- In a sibling library: Go:
synctestmakes time virtual ↗ - In a sibling library: Go:
synctest.Waitinstead of a sleep ↗ - In the books: Async Rust, Maxwell Flitton, Caroline Morton — ch. 11, 'Testing' → 'Mocking Async Code'
- In the books: Modern Multithreading, Richard H. Carver, Kuo-Chung Tai — ch. 2, 'The Critical Section Problem' → 'Tracing and Replay for Shared Variables'