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.
Test deterministici delle condizioni di razza utilizzando barriere e promesse differite. Sostituisce i test di temporizzazione instabili basati su setTimeout con un controllo di interleaving riproducibile. Fonte: apankov1/quality-engineering.