Path: redb-route/tests/redb.Route.Tests.Sql/E2E/Base/PollListDeliveryTestsBase.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.Sql/E2E/Base/PollListDeliveryTestsBase.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Sql; using redb.Route.Tests.Sql.E2E.Infrastructure; using Xunit.Abstractions; namespace redb.Route.Tests.Sql.E2E.Base; /// /// A streaming poll delivered as one list (outputType=StreamList, pollDelivery=List, Apache Camel /// useIterator=false with a result set iterator): the route reads the rows from the open reader; onSuccess runs /// once, after the reader is closed, so it shares the consumer transaction on every driver. /// public abstract class PollListDeliveryTestsBase(ITestOutputHelper output) : IAsyncLifetime { private SqlE2EDatabase? _db; /// The provider under test. protected abstract SqlE2EProvider Provider { get; } private SqlE2EDatabase Db => _db ?? throw new InvalidOperationException("The table is created in InitializeAsync."); /// public async Task InitializeAsync() { _db = await SqlE2EDatabase.CreateAsync(Provider); for (var id = 1; id <= 3; id++) await Db.ExecuteAsync(Provider.InsertLiteral(Db.Table, id, "new")); } /// public async Task DisposeAsync() { try { if (_db is not null) await _db.DisposeAsync(); } finally { (Provider as IDisposable)?.Dispose(); } } [Fact] public async Task StreamListAsList_Transacted_OnSuccessOnceAfterReaderClosed() { var factory = Db.CreateConnectionFactory(); await using var context = new RouteContext(); var endpoint = SqlEndpointHarness.CreateEndpoint(context, factory, $"SELECT id, val FROM {Db.Table} ORDER BY id", new() { ["mode"] = "Poll", ["outputType"] = "StreamList", ["pollDelivery"] = "List", ["transacted"] = "true", ["onSuccess"] = $"UPDATE {Db.Table} SET val = 'done'", ["delay"] = "100", ["repeatCount"] = "1", }); var exchanges = 0; var rowsRead = 0; var processor = Substitute.For(); processor.Process(Arg.Any(), Arg.Any()) .Returns(async ci => { exchanges++; if (ci.Arg().In.Body is IAsyncEnumerable> stream) await foreach (var _ in stream) rowsRead++; }); var consumer = (SqlConsumer)endpoint.CreateConsumer(processor); var thrown = await Outcome.Of(() => consumer.Poll(CancellationToken.None)); var values = string.Join(",", (await Db.QueryAsync($"SELECT val FROM {Db.Table} ORDER BY id")).Select(r => r[0])); output.WriteLine($"[probe] {Provider.Name}: StreamList as one list, transacted: poll={Outcome.Describe(thrown)}, " + $"exchanges={exchanges}, rows read={rowsRead}, rows={values}, open={factory.OpenConnections}"); thrown.Should().BeNull(Outcome.Describe(thrown)); exchanges.Should().Be(1, "the whole poll is one exchange"); rowsRead.Should().Be(3, "the route reads the rows from the stream"); values.Should().Be("done,done,done", "onSuccess ran once, after the reader was closed, in the consumer transaction"); factory.OpenConnections.Should().Be(0); } }