Race Condition
Coupons occasionally oversell while one test run looks normal. Reproduce the race with concurrent timing, fix it, and verify repeatedly.
Coupons occasionally oversell while one test run looks normal. Reproduce the race with concurrent timing, fix it, and verify repeatedly.
The result depends on request timing.
Problem and key mechanism: Both requests start from one coupon, and different read-write interleavings sometimes issue two; have the concurrent test record each read and write's request ID, value, and time so timing evidence returns to the same run.
Verify stability across repeated runs: After an atomic update or correctly scoped lock, repeated runs yield one success and stock 0. This does not prove every race is gone.
A second scenario: avatar management: If a user uploads a new avatar and immediately cancels it, different upload and delete completion orders can make the avatar reappear. Record the timing and repeat the test to verify the final state always follows the last action.
Create a repeatable concurrent test for the last coupon so two requests claim from the same initial state. Record request IDs, read values, writes, and timing. Reproduce the race, then fix it with an atomic update or correctly scoped lock. Repeat the run and verify exactly one success and remaining stock 0 every time; do not treat one pass as proof.