← Lessons

quiz vs the machine

Gold1350

Concurrency

Stress Testing Concurrent Code

Run many threads under load to shake out interleavings that rarely happen.

4 min read · core · beat Gold to climb

Why one run is not enough

A correct looking concurrent function may fail only under a specific interleaving. A single test almost always hits the easy schedule and passes.

How stress testing helps

A stress test runs the same operations across many threads for many iterations, hoping the scheduler eventually produces a dangerous interleaving:

  • raise thread counts above core counts to force context switches
  • repeat the test thousands of times
  • add random short delays to vary timing

The more interleavings you sample, the higher the chance of catching a latent bug.

Its limits

Stress testing is probabilistic. It can raise confidence but never proves correctness, and a rare bug may still slip through because the harmful schedule was never sampled.

Key idea

Stress testing samples many interleavings by piling on threads and iterations, raising the odds of hitting a rare bug while never proving its absence.

Check yourself

Answer to earn rating on the learn ladder.

1. Why use more threads than cores in a stress test?

2. What is the key limitation of stress testing?