Skip to content

test(wallets): Retry wallet writes on 409 in integration specs - #381

Merged
groyoh merged 1 commit into
mainfrom
test/ing-777-retry-wallet-conflicts
Oct 29, 2026
Merged

groyoh merged 1 commit into
mainfrom
test/ing-777-retry-wallet-conflicts

Conversation

@groyoh

@groyoh groyoh commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

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, then last_ongoing_balance_sync_at with touch_all, which also bumps lock_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 raises ActiveRecord::StaleObjectError, which Rails renders as a 409.

Description

A retry_on_conflict helper 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 of spec/integration/wallets_spec.rb and spec/integration/customers/wallets_spec.rb now use it.

Fixes ING-777

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.
@groyoh
groyoh merged commit b4607ce into main Oct 29, 2026
6 checks passed
@groyoh
groyoh deleted the test/ing-777-retry-wallet-conflicts branch October 29, 2026 14:32
@groyoh

groyoh commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @toommz for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants