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