Path: redb-route/tests/redb.Route.Tests/Processors/DelayProcessorTests.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/DelayProcessorTests.cs
----
using AwesomeAssertions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Tests.Processors;
/// Tests for .
public class DelayProcessorTests
{
/// Delay actually waits approximately the specified time.
[Fact]
public async Task Process_DelaysApproximately()
{
var processor = new DelayProcessor(TimeSpan.FromMilliseconds(100));
var sw = System.Diagnostics.Stopwatch.StartNew();
await processor.Process(new Exchange());
sw.Elapsed.Should().BeGreaterThanOrEqualTo(TimeSpan.FromMilliseconds(80));
}
/// Zero delay completes immediately.
[Fact]
public async Task Process_ZeroDelay_Immediate()
{
var processor = new DelayProcessor(TimeSpan.Zero);
var sw = System.Diagnostics.Stopwatch.StartNew();
await processor.Process(new Exchange());
sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(50));
}
/// Cancellation during delay throws OperationCanceledException.
[Fact]
public async Task Process_Cancelled_Throws()
{
var processor = new DelayProcessor(TimeSpan.FromSeconds(10));
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(50));
var act = () => processor.Process(new Exchange(), cts.Token);
await act.Should().ThrowAsync();
}
/// Negative delay throws ArgumentOutOfRangeException.
[Fact]
public void Constructor_NegativeDelay_Throws()
{
var act = () => new DelayProcessor(TimeSpan.FromSeconds(-1));
act.Should().Throw();
}
/// Delay property returns configured value.
[Fact]
public void Delay_ReturnsConfigured()
{
var delay = TimeSpan.FromMilliseconds(250);
var processor = new DelayProcessor(delay);
processor.Delay.Should().Be(delay);
}
}