public void Backoff_WithFastFirstEqualToTrue_ResultIsZero() { // Arrange var minDelay = TimeSpan.FromMilliseconds(1); var maxDelay = TimeSpan.FromMilliseconds(2); const int retryCount = 3; const bool fastFirst = true; const int seed = 1; // Act IEnumerable <TimeSpan> result = Backoff.DecorrelatedJitter(minDelay, maxDelay, retryCount, fastFirst, seed); // Assert result.Should().NotBeNull(); result.Should().HaveCount(retryCount); bool first = true; foreach (TimeSpan timeSpan in result) { if (first) { timeSpan.Should().Be(TimeSpan.FromMilliseconds(0)); first = false; } else { timeSpan.Should().BeGreaterOrEqualTo(minDelay); timeSpan.Should().BeLessOrEqualTo(maxDelay); } } }
public void Backoff_WithRetryCountLessThanZero_ThrowsException() { // Arrange var minDelay = TimeSpan.FromMilliseconds(1); var maxDelay = TimeSpan.FromMilliseconds(2); const int retryCount = -1; const bool fastFirst = false; const int seed = 1; // Act Action act = () => Backoff.DecorrelatedJitter(minDelay, maxDelay, retryCount, fastFirst, seed); // Assert act.Should().Throw <ArgumentOutOfRangeException>() .And.ParamName.Should().Be("retryCount"); }
public void Backoff_WithRetryEqualToZero_ResultIsEmpty() { // Arrange var minDelay = TimeSpan.FromMilliseconds(1); var maxDelay = TimeSpan.FromMilliseconds(2); const int retryCount = 0; const bool fastFirst = false; const int seed = 1; // Act IEnumerable <TimeSpan> result = Backoff.DecorrelatedJitter(minDelay, maxDelay, retryCount, fastFirst, seed); // Assert result.Should().NotBeNull(); result.Should().BeEmpty(); }
public void Backoff_ResultIsInRange() { // Arrange var minDelay = TimeSpan.FromMilliseconds(10); var maxDelay = TimeSpan.FromMilliseconds(100); const int retryCount = 3; const bool fastFirst = false; const int seed = 100; // Act IEnumerable <TimeSpan> result = Backoff.DecorrelatedJitter(minDelay, maxDelay, retryCount, fastFirst, seed); // Assert result.Should().NotBeNull(); result.Should().HaveCount(retryCount); foreach (TimeSpan timeSpan in result) { timeSpan.Should().BeGreaterOrEqualTo(minDelay); timeSpan.Should().BeLessOrEqualTo(maxDelay); } }