Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Testing
Testinghard

How do you test asynchronous or concurrent code?

Tags
#async#concurrency#determinism
Back to categoryPractice quiz

Answer

Use deterministic clocks, await completion, and assert on outcomes. For concurrency, test invariants, use controlled schedulers, and avoid timing-based sleeps.

Advanced answer

Deep dive

Stability comes from determinism:

  • Use fake timers or virtual clocks.
  • Await all async work and flush queues.
  • For concurrency, test invariants (no lost updates, no duplicates).
  • Use stress tests to increase interleavings.

Examples

Async test pattern:

await doWork();
await flushJobs();
expect(state).toEqual(...)

Common pitfalls

  • Using sleep instead of waiting for a condition.
  • Not awaiting tasks (tests pass incorrectly).
  • Relying on real time or network.

Interview follow-ups

  • How do you test race conditions deterministically?
  • When do you use stress tests vs unit tests?
  • How do you test idempotency under concurrency?

Related questions

Operating Systems
What causes deadlocks and how can you prevent them?
#deadlock#locks#concurrency
Operating Systems
Processes vs threads — what’s the difference and when does it matter?
#processes#threads#concurrency
JavaScript
What does Promise.all do and when would you use it?
#promises#async
JavaScript
How do Promises work and how do they differ from callbacks?
#promises#async
JavaScript
What is the event loop and how do microtasks differ from macrotasks?
#event-loop#async
PostgreSQL
MVCC in Postgres: why don’t readers block writers?
#postgres#mvcc#concurrency