Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Testing/CoreTests/ErrorHandling/BackoffTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Wolverine.ErrorHandling;
using Xunit;

namespace CoreTests.ErrorHandling;

public class BackoffTests
{
[Fact]
public void ConstantBackoffWithZeroRetriesShouldByEmpty()
{
var backoff = Backoff.Constant(10, 0);
backoff.ShouldNotBeNull();
backoff.Count().ShouldBe(0);
}

[Fact]
public void ConstantBackoffWithNonZeroRetriesShouldYieldDelay()
{
const int maxRetries = 1;
const int delay = 10;

var backoff = Backoff.Constant(delay, maxRetries);
backoff.Count().ShouldBe(maxRetries);
backoff.First().Milliseconds.ShouldBe(delay);
}
}
11 changes: 11 additions & 0 deletions src/Wolverine/ErrorHandling/Backoff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Wolverine.ErrorHandling;

public class Backoff
{
public static IEnumerable<TimeSpan> Constant(int delay, int maxRetries)
{
return maxRetries == 0
? new List<TimeSpan>()
: Enumerable.Range(1, maxRetries).Select(i => TimeSpan.FromMilliseconds(delay));
}
}