test(ledger): prove the no-lost-update invariant under concurrent posting - #151
Merged
Conversation
added 2 commits
June 16, 2026 21:53
…ting Add ConcurrentPostersIT: 100 virtual-thread posters commit distinct balanced transactions to one shared account pair through the idempotency-wrapped path, where the bounded optimistic-retry absorbs the @Version conflicts on the shared account_balances rows. Asserts the final balance equals the algebraic sum of the committed postings, every failure is a typed ConcurrencyConflictException with no raw optimistic-lock leak, and entry/transaction row counts match the success count. The contract is asserted over the observed success count so the test is non-flaky regardless of how the scheduler resolves contention. Test-only slice, no production change. Closes #56
Isolate the optimistic UPDATE+retry contention path from the cold-start account_balances INSERT race (filed as #152), which the retry loop does not cover. Adjust expected counts to include the warm-up posting.
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.
What
Adds
ConcurrentPostersIT, a Testcontainers PostgreSQL 17 concurrency test that proves the ledger's no-lost-update invariant under real contention. 100 virtual-thread posters, released together by aCountDownLatchstart-gate, each commit a distinct balancedDEBIT +100.00 / CREDIT -100.00transaction to one shared account pair through the idempotency-wrapped path (idempotencyService.execute { transactionService.post(...) }), the only path where the bounded optimistic-retry absorbs the@Versionconflicts on the sharedaccount_balancesrows.Asserted contract (non-flaky, S = observed success count)
balance == 100.00 * SviacompareTo).ConcurrencyConflictException; any other throwable (including a rawOptimisticLockingFailureExceptionor a pool-timeout) is captured first and fails the test loudly.All assertions are phrased over the observed S, so the test passes on every CI run regardless of how the scheduler resolves 100-way contention (default
max-attempts=3, no backoff, means many posters legitimately resolve to a typed 503; that is correct and asserted).Notes
@DataJpaTest+@Transactional(NOT_SUPPORTED)so worker threads commit and the read-back sees committed cross-thread state; mirrors theAuditRetryTopologyITharness.maximum-pool-size=16, explicitconnection-timeout) to keep real parallelism while staying within the shared-container budget;@AfterEach outboxRepository.deleteAll()keeps sibling global-count ITs green.Closes #56