Path: redb-route/tests/redb.Route.Tests/Processors/ParallelTransactionIsolationTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests/Processors/ParallelTransactionIsolationTests.cs ---- using System.Collections.Concurrent; using System.Transactions; using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Processors; namespace redb.Route.Tests.Processors; /// /// Verifies that parallel Splitter / Multicast branches run under a private /// clone of the ambient transaction instead of sharing one /// across threads (which System.Transactions forbids). /// public class ParallelTransactionIsolationTests { [Fact] public async Task Multicast_Parallel_InsideTransaction_EachBranchUnderDependentClone() { var kinds = new ConcurrentBag(); var multicast = new MulticastProcessor(parallelProcessing: true) .AddTarget(new DelegateProcessor(_ => kinds.Add(TxKind()))) .AddTarget(new DelegateProcessor(_ => kinds.Add(TxKind()))) .AddTarget(new DelegateProcessor(_ => kinds.Add(TxKind()))); using (var scope = new TransactionScope( TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled)) { await multicast.Process(new Exchange(new Message("data"))); scope.Complete(); // must not throw / block — all dependents already signalled Complete() } kinds.Should().HaveCount(3); kinds.Should().OnlyContain(k => k == nameof(DependentTransaction)); } [Fact] public async Task Splitter_Parallel_InsideTransaction_EachBranchUnderDependentClone() { var kinds = new ConcurrentBag(); var splitter = new SplitterProcessor( ex => (IEnumerable)ex.In.Body!, new DelegateProcessor(_ => kinds.Add(TxKind())), parallelProcessing: true, stopOnException: false); using (var scope = new TransactionScope( TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled)) { await splitter.Process(new Exchange(new Message(new object[] { "a", "b", "c", "d" }))); scope.Complete(); } kinds.Should().HaveCount(4); kinds.Should().OnlyContain(k => k == nameof(DependentTransaction)); } [Fact] public async Task Multicast_Parallel_NoAmbientTransaction_IsPassthrough() { var sawTransaction = new ConcurrentBag(); var multicast = new MulticastProcessor(parallelProcessing: true) .AddTarget(new DelegateProcessor(_ => sawTransaction.Add(Transaction.Current != null))) .AddTarget(new DelegateProcessor(_ => sawTransaction.Add(Transaction.Current != null))); await multicast.Process(new Exchange(new Message("data"))); sawTransaction.Should().HaveCount(2); sawTransaction.Should().OnlyContain(seen => seen == false); // no scope created when no ambient TX } private static string TxKind() => Transaction.Current?.GetType().Name ?? "(none)"; }