-
Testing
Test what happens when things happen at the same time
Write concurrency tests for double submissions, race conditions on counters, and simultaneous edits.
Free Prompt
Some bugs only show up when two things happen at once, and I want tests for the ones in my app before users find them.
Look through my app for the classic concurrency trouble spots and write tests for the ones that exist:
1. Double submission: fire the same form submission, checkout, or payment request twice in quick succession and assert the result happens once (one order, one charge, one record), not twice.
2. Counter races: if my app increments or decrements anything (credits, inventory, usage counts, likes), fire concurrent updates and assert the final value is correct, not lost to a read-modify-write race.
3. Uniqueness under concurrency: try creating two records with the same unique value (email, username, slug) simultaneously and assert one fails cleanly instead of both succeeding or one crashing with an ugly database error.
4. Simultaneous edits: two updates to the same record at the same time should leave it in a coherent state, not a torn mix of both.
Use whatever my stack provides for firing concurrent requests in tests. Where my database supports them, the fixes should live at the database level (unique constraints, atomic operations, transactions), and the tests should verify those actually work.
If a test reveals a genuine race, don't patch it silently. Show me the failing behavior and the fix options first.
When done, run the tests repeatedly (a few iterations) since race bugs can be intermittent, and report which invariants hold and which don't.
What This Does / How This Helps
This tests the concurrency cases: double-submitted payments, counter races, duplicate unique values created at the same moment, and simultaneous edits. These bugs are invisible in manual testing because you can't click fast enough to trigger them. Real traffic triggers them in the first week: a double-tapped buy button creates two charges, a credit counter loses updates, two signups claim the same username. The fixes belong in the database and the tests prove they're actually working, which is the only version of 'it works' that counts.
Want to skip doing this by hand?
Fortivibe audits your app for all of the areas these prompts cover (and more).