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.
Детерминированное тестирование состояния гонки с использованием барьеров и отложенных обещаний. Заменяет ненадежные тесты синхронизации на основе setTimeout на воспроизводимое управление чередованием. Источник: apankov1/quality-engineering.