Path: redb-route/tests/redb.Route.Tests/Core/DrainableConsumerTrackingTests.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/Core/DrainableConsumerTrackingTests.cs
----
using System.Diagnostics;
using redb.Route.Abstractions;
using redb.Route.Components;
using redb.Route.Processors;
using redb.Route.Telemetry;
using redb.Route.Tests.Telemetry;
namespace redb.Route.Tests.Core;
///
/// DrainableConsumer.ProcessWithTracking is the one place a polling consumer hands an exchange to the route. A
/// failure that escapes the pipeline — a cancellation the consumer did not ask for, e.g. an HttpClient timeout through
/// an error handler that rethrows it — lands on the exchange, so a consumer deciding on the outcome (delete after read,
/// move on failure) sees a failed route instead of a clean one; the receive span, when given, is marked by the same
/// rule as every transport; and only the consumer's own stop is passed on.
///
public class DrainableConsumerTrackingTests
{
private sealed class Probe(IProcessor processor, IEndpoint endpoint) : global::redb.Route.Core.DrainableConsumer(processor)
{
protected override IEndpoint ConsumerEndpoint => endpoint;
protected override string ConsumerName => "probe";
protected override Task RunAsync(CancellationToken pollCt, CancellationToken processingCt) => Task.CompletedTask;
public Task Track(IExchange exchange, CancellationToken ct) => ProcessWithTracking(exchange, ct);
public Task Track(IExchange exchange, TransportSpan span, CancellationToken ct) => ProcessWithTracking(exchange, span, ct);
}
private sealed class StubEndpoint(string uri) : IEndpoint
{
public EndpointUri Uri { get; } = global::redb.Route.Core.EndpointUriParser.Parse(uri);
public IComponent Component { get; } = new TimerComponent();
public IProducer CreateProducer() => throw new NotSupportedException();
public IConsumer CreateConsumer(IProcessor processor) => throw new NotSupportedException();
public Task Start(CancellationToken ct = default) => Task.CompletedTask;
public Task Stop(CancellationToken ct = default) => Task.CompletedTask;
}
private static (Probe Consumer, string Endpoint) Consumer(Func route)
{
var endpoint = $"probe://tracking-{Guid.NewGuid():N}";
return (new Probe(new DelegateProcessor(route), new StubEndpoint(endpoint)), endpoint);
}
private static TransportSpan Span(string endpoint)
=> RouteTelemetryExtensions.StartConsumerSpan