diff --git a/src/Polly.Core/DelayBackoffType.cs b/src/Polly.Core/DelayBackoffType.cs index 4f86cd205ed..f08184c6b2f 100644 --- a/src/Polly.Core/DelayBackoffType.cs +++ b/src/Polly.Core/DelayBackoffType.cs @@ -1,4 +1,4 @@ -namespace Polly.Retry; +namespace Polly; /// /// The backoff type used by the strategies. diff --git a/src/Polly.Core/PublicAPI.Unshipped.txt b/src/Polly.Core/PublicAPI.Unshipped.txt index 03fcf88ed83..d690461ed16 100644 --- a/src/Polly.Core/PublicAPI.Unshipped.txt +++ b/src/Polly.Core/PublicAPI.Unshipped.txt @@ -84,6 +84,10 @@ Polly.CircuitBreaker.OnCircuitOpenedArguments.OnCircuitOpenedArguments( Polly.CircuitBreaker.OnCircuitOpenedArguments.OnCircuitOpenedArguments(Polly.ResilienceContext! context, Polly.Outcome outcome, System.TimeSpan breakDuration, bool isManual) -> void Polly.CircuitBreaker.OnCircuitOpenedArguments.Outcome.get -> Polly.Outcome Polly.CircuitBreakerResiliencePipelineBuilderExtensions +Polly.DelayBackoffType +Polly.DelayBackoffType.Constant = 0 -> Polly.DelayBackoffType +Polly.DelayBackoffType.Exponential = 2 -> Polly.DelayBackoffType +Polly.DelayBackoffType.Linear = 1 -> Polly.DelayBackoffType Polly.ExecutionRejectedException Polly.ExecutionRejectedException.ExecutionRejectedException() -> void Polly.ExecutionRejectedException.ExecutionRejectedException(string! message) -> void @@ -281,10 +285,6 @@ Polly.ResilienceStrategyOptions Polly.ResilienceStrategyOptions.Name.get -> string? Polly.ResilienceStrategyOptions.Name.set -> void Polly.ResilienceStrategyOptions.ResilienceStrategyOptions() -> void -Polly.Retry.DelayBackoffType -Polly.Retry.DelayBackoffType.Constant = 0 -> Polly.Retry.DelayBackoffType -Polly.Retry.DelayBackoffType.Exponential = 2 -> Polly.Retry.DelayBackoffType -Polly.Retry.DelayBackoffType.Linear = 1 -> Polly.Retry.DelayBackoffType Polly.Retry.OnRetryArguments Polly.Retry.OnRetryArguments.AttemptNumber.get -> int Polly.Retry.OnRetryArguments.Context.get -> Polly.ResilienceContext! @@ -309,7 +309,7 @@ Polly.Retry.RetryPredicateArguments.RetryPredicateArguments(Polly.Resil Polly.Retry.RetryStrategyOptions Polly.Retry.RetryStrategyOptions.RetryStrategyOptions() -> void Polly.Retry.RetryStrategyOptions -Polly.Retry.RetryStrategyOptions.BackoffType.get -> Polly.Retry.DelayBackoffType +Polly.Retry.RetryStrategyOptions.BackoffType.get -> Polly.DelayBackoffType Polly.Retry.RetryStrategyOptions.BackoffType.set -> void Polly.Retry.RetryStrategyOptions.Delay.get -> System.TimeSpan Polly.Retry.RetryStrategyOptions.Delay.set -> void diff --git a/src/Polly.Core/Retry/RetryHelper.cs b/src/Polly.Core/Retry/RetryHelper.cs index 2bca0fdc5ae..c2afdcf13bd 100644 --- a/src/Polly.Core/Retry/RetryHelper.cs +++ b/src/Polly.Core/Retry/RetryHelper.cs @@ -20,7 +20,7 @@ public static TimeSpan GetRetryDelay(DelayBackoffType type, bool jitter, int att } } - private static TimeSpan GetRetryDelayCore(RetryBackoffType type, bool jitter, int attempt, TimeSpan baseDelay, ref double state, Func randomizer) + private static TimeSpan GetRetryDelayCore(DelayBackoffType type, bool jitter, int attempt, TimeSpan baseDelay, ref double state, Func randomizer) { if (baseDelay == TimeSpan.Zero) { diff --git a/src/Polly.Core/Utils/TimeProviderExtensions.cs b/src/Polly.Core/Utils/TimeProviderExtensions.cs index d61a02c3edf..de2d7354056 100644 --- a/src/Polly.Core/Utils/TimeProviderExtensions.cs +++ b/src/Polly.Core/Utils/TimeProviderExtensions.cs @@ -23,6 +23,11 @@ public static Task DelayAsync(this TimeProvider timeProvider, TimeSpan delay, Re context.CancellationToken.ThrowIfCancellationRequested(); + if (delay == TimeSpan.MaxValue) + { + delay = System.Threading.Timeout.InfiniteTimeSpan; + } + if (context.IsSynchronous) { #pragma warning disable CA1849 diff --git a/test/Polly.Core.Tests/Retry/RetryHelperTests.cs b/test/Polly.Core.Tests/Retry/RetryHelperTests.cs index 607ef922eb0..f5d78eac08e 100644 --- a/test/Polly.Core.Tests/Retry/RetryHelperTests.cs +++ b/test/Polly.Core.Tests/Retry/RetryHelperTests.cs @@ -100,7 +100,7 @@ public void GetRetryDelay_Overflow_ReturnsMaxTimeSpan() { double state = 0; - RetryHelper.GetRetryDelay(RetryBackoffType.Exponential, false, 1000, TimeSpan.FromDays(1), ref state, _randomizer).Should().Be(TimeSpan.MaxValue); + RetryHelper.GetRetryDelay(DelayBackoffType.Exponential, false, 1000, TimeSpan.FromDays(1), ref state, _randomizer).Should().Be(TimeSpan.MaxValue); } [InlineData(1)] diff --git a/test/Polly.Core.Tests/Utils/TimeProviderExtensionsTests.cs b/test/Polly.Core.Tests/Utils/TimeProviderExtensionsTests.cs index b36badfc87f..82deb0fd4d8 100644 --- a/test/Polly.Core.Tests/Utils/TimeProviderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Utils/TimeProviderExtensionsTests.cs @@ -99,4 +99,26 @@ await TestUtilities.AssertWithTimeoutAsync(async () => await Assert.ThrowsAnyAsync(() => timeProvider.DelayAsync(delay, context)); }); } + + [Fact] + public async Task DelayAsync_MaxTimeSpan_DoesNotThrow() + { + var delay = TimeSpan.MaxValue; + + await TestUtilities.AssertWithTimeoutAsync(async () => + { + using var cancellation = new CancellationTokenSource(); + var timeProvider = TimeProvider.System; + var context = ResilienceContextPool.Shared.Get(); + context.Initialize(isSynchronous: false); + context.CancellationToken = cancellation.Token; + + var delayTask = timeProvider.DelayAsync(delay, context); + delayTask.Wait(TimeSpan.FromMilliseconds(10)).Should().BeFalse(); + + cancellation.Cancel(); + + await delayTask.Invoking(t => t).Should().ThrowAsync(); + }); + } } diff --git a/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs b/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs index 7de6d42d2c8..d134ff2e854 100644 --- a/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs +++ b/test/Polly.Extensions.Tests/Issues/IssuesTests.StrategiesPerEndpoint_1365.cs @@ -4,7 +4,6 @@ using Microsoft.Extensions.Options; using Polly.DependencyInjection; using Polly.Registry; -using Polly.Retry; using Polly.Timeout; namespace Polly.Extensions.Tests.Issues; diff --git a/test/Polly.Specs/ResiliencePipelineConversionExtensionsTests.cs b/test/Polly.Specs/ResiliencePipelineConversionExtensionsTests.cs index 9837159aa6d..eb5fe71be9e 100644 --- a/test/Polly.Specs/ResiliencePipelineConversionExtensionsTests.cs +++ b/test/Polly.Specs/ResiliencePipelineConversionExtensionsTests.cs @@ -1,3 +1,4 @@ +using Polly; using Polly.TestUtils; namespace Polly.Specs;