fix(test): lock AllItemsReceived state in batch_processing tests#2692
Merged
jeremydmiller merged 1 commit intomainfrom May 7, 2026
Merged
fix(test): lock AllItemsReceived state in batch_processing tests#2692jeremydmiller merged 1 commit intomainfrom
jeremydmiller merged 1 commit intomainfrom
Conversation
`MartenTests.batch_processing.end_to_end_with_tenancy` has been failing on every recent Marten CI run with an `AggregateException` of NREs out of `AllItemsReceived.IsCompleted`. Root cause: in the multi-tenant variant the "blue" and "green" tenant batches complete in parallel and both call `Record(EnvelopeRecord)` from the tracking infrastructure on whichever thread the handler finishes on. The helper fed the records into a plain `List<BatchItem>` via `AddRange`, which is not thread-safe — concurrent callers race on the internal array's resize and writes, leaving null slots that surface as NRE when the polling thread reads `r.Id` in the `IsCompleted` predicate. Local reproduction: 1/10 fail without the fix on a fast box, deterministically failing in CI on slower runners (consistent failure across the last several Marten runs, retried twice and still red). With this lock both Record (writer) and IsCompleted (reader) see a consistent snapshot — verified locally 15/15 plus the sibling `end_to_end_with_durable` test (which uses the same helper) still passes. No production code is touched; the lock lives entirely in the test helper class. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
MartenTests.batch_processing.end_to_end_with_tenancyhas been failing on every recent Marten CI run with anAggregateExceptionof NREs out ofAllItemsReceived.IsCompleted. Root cause: in the multi-tenant variant the "blue" and "green" tenant batches complete in parallel and both callRecord(EnvelopeRecord)from the tracking infrastructure on whichever thread the handler finishes on. The helper fed the records into a plainList<BatchItem>viaAddRange, which is not thread-safe — concurrent callers race on the internal array's resize and writes, leaving null slots that surface as NRE when the polling thread readsr.Idin theIsCompletedpredicate.Record(writer) andIsCompleted(reader) so the polling thread sees a consistent snapshot.Repro / verification
25434414670,25391326016,25380002472,25373294046,25492035820).end_to_end_with_tenancy; siblingend_to_end_with_durable(which uses the same helper) also passes.Test plan
dotnet test --filter FullyQualifiedName=MartenTests.batch_processing.end_to_end_with_tenancy— 15/15 passeddotnet test --filter FullyQualifiedName~MartenTests.batch_processing— 2/2 passedNote
This PR is also serving to put the Marten CI under load while you watch for any timeout regression.
🤖 Generated with Claude Code