Explanation

Retries and idempotency in software testing

What should a test check when the same operation can be retried?

Check the lasting effect of repeating the same logical request. Where the contract promises idempotency, a retry should leave the business outcome equivalent to one successful attempt. Inspect the recorded state and any promised side effects after both attempts.

Why might a successful operation be repeated?

A service can commit a change before its caller receives the acknowledgement. The caller sees a timeout and tries again. A queue can also deliver the same message twice. Use the contract’s definition of a duplicate, including the identity of the request and any expiry period.

Which result should the test inspect?

Read back the business record and count the promised effects, such as allocated seats or issued vouchers. An initial request and a replay can legitimately have different response details. The contract determines which effects and response guarantees must stay consistent.

Worked example

Two acknowledgements, one voucher

Process one reward event, then deliver it again using the same event ID. Check that a fresh read finds one voucher for that event and that the member’s reward balance was reduced once. A test that stops at the handler’s second acknowledgement would miss a duplicate voucher.

Try it on your pull request

Choose a change in your repository and tell Cue April what should happen. Review the proposed checks before they run.

Try Cue April on your repository