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.
Pruebas deterministas de condiciones de carrera utilizando barreras y promesas diferidas. Reemplaza las inestables pruebas de sincronización basadas en setTimeout con control de entrelazado reproducible. Fuente: apankov1/quality-engineering.