Repository navigation
test(wallets): Retry wallet writes on 409 in integration specs - #381
Merged
Merged
Conversation
After a top-up, the wallet refresh job writes the wallet twice: the ongoing balance, then last_ongoing_balance_sync_at, which also bumps lock_version. The second write is not visible through the API, so the specs cannot wait for it. A wallet update or terminate sent in between fails with a 409 (ActiveRecord::StaleObjectError) and is rolled back. The wallet update and destroy examples now go through retry_on_conflict, which sends the call again on a 409, up to 5 times.
toommz
approved these changes
Oct 29, 2026
Contributor
Author
|
Thanks @toommz for the review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The wallet update and destroy integration specs fail at random with
HTTP 409 {"status":409,"error":"Conflict"}.Wallets use optimistic locking (
lock_version). After a top-up, the wallet refresh job writes the wallet twice: first the ongoing balance, thenlast_ongoing_balance_sync_atwithtouch_all, which also bumpslock_version. The specs wait until the ongoing balance is visible, but the second write changes nothing the API returns, so they cannot wait for it. A wallet write sent in between raisesActiveRecord::StaleObjectError, which Rails renders as a 409.Description
A
retry_on_conflicthelper sends the call again on a 409, up to 5 times with a short pause. The failed request is rolled back, so a retry is safe. The update and destroy examples ofspec/integration/wallets_spec.rbandspec/integration/customers/wallets_spec.rbnow use it.Fixes ING-777