concurrency-testinglisted
Install: claude install-skill robsonkades/agent-skills
# Concurrency Testing
## Purpose
Get concurrency defects to fail a build. Most never do, because the tests that would catch
them are the ones nobody writes: cancellation, interruption, timeout, rejection, and the
behaviour of a limit at its boundary. What does get written — a test that starts two threads
and asserts the happy path — is the one that proves the least.
The second purpose is calibration. A green concurrency test is weak evidence, and treating it
as strong evidence is how a race gets shipped with confidence.
## Workflow
The ordinary examples use Java 21+ final APIs and JUnit Jupiter; the structured-scope example
uses Java 25 preview. Inspect compiler release/toolchains, CI JDK, resolved test libraries and
timeout mode before adapting them. Keep the project's baseline and existing test framework;
do not upgrade Java or enable preview merely to use this skill.
1. **Separate the logic from the concurrency.** Inject the executor. Test the logic with a
same-thread executor, deterministically; test the concurrency separately and explicitly.
2. **Write the failure-path tests first**, because they are the ones that will otherwise not
exist: cancel mid-flight, interrupt, time out, reject at the limit, fail the dependency.
3. **Replace every sleep with a synchronisation point** — a latch, a barrier, `Awaitility`
with a bound. A sleep is either a flaky test or a slow one, and usually both.
4. **Assert invariants, not schedules.** After owned work terminates, a