Instead of setTimeout (flaky) or sleep (slow), use barriers to pause execution at exact interleave points. The test controls when each concurrent operation proceeds, making race condition tests deterministic and reproducible on every run.
When to use: Testing concurrent operations, flush conflicts, parallel mutations, race windows between read and write, lock contention scenarios, any code where timing affects correctness.
When not to use: Sequential-only code, simple unit tests, UI components, read-only operations, code with no concurrency concerns.
Deterministische Race-Condition-Tests unter Verwendung von Barrieren und aufgeschobenen Versprechen. Ersetzt flockige setTimeout-basierte Timing-Tests durch reproduzierbare Interleaving-Steuerung. Quelle: apankov1/quality-engineering.