diff --git a/src/Polly.Core/CircuitBreaker/CircuitBreakerConstants.cs b/src/Polly.Core/CircuitBreaker/CircuitBreakerConstants.cs index 6b31f0794cd..cf4adc1457c 100644 --- a/src/Polly.Core/CircuitBreaker/CircuitBreakerConstants.cs +++ b/src/Polly.Core/CircuitBreaker/CircuitBreakerConstants.cs @@ -2,6 +2,8 @@ namespace Polly.CircuitBreaker; internal static class CircuitBreakerConstants { + public const string DefaultName = "CircuitBreaker"; + public const string OnCircuitClosed = "OnCircuitClosed"; public const string OnHalfOpenEvent = "OnCircuitHalfOpened"; diff --git a/src/Polly.Core/CircuitBreaker/CircuitBreakerStrategyOptions.TResult.cs b/src/Polly.Core/CircuitBreaker/CircuitBreakerStrategyOptions.TResult.cs index 7f371beff8a..42e47cf7de2 100644 --- a/src/Polly.Core/CircuitBreaker/CircuitBreakerStrategyOptions.TResult.cs +++ b/src/Polly.Core/CircuitBreaker/CircuitBreakerStrategyOptions.TResult.cs @@ -22,6 +22,11 @@ namespace Polly.CircuitBreaker; /// public class CircuitBreakerStrategyOptions : ResilienceStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public CircuitBreakerStrategyOptions() => Name = CircuitBreakerConstants.DefaultName; + /// /// Gets or sets the failure-to-success ratio at which the circuit will break. /// diff --git a/src/Polly.Core/Fallback/FallbackConstants.cs b/src/Polly.Core/Fallback/FallbackConstants.cs index bc5913cf7a9..de2a9609748 100644 --- a/src/Polly.Core/Fallback/FallbackConstants.cs +++ b/src/Polly.Core/Fallback/FallbackConstants.cs @@ -2,6 +2,8 @@ namespace Polly.Fallback; internal static class FallbackConstants { + public const string DefaultName = "Fallback"; + public const string OnFallback = "OnFallback"; } diff --git a/src/Polly.Core/Fallback/FallbackStrategyOptions.TResult.cs b/src/Polly.Core/Fallback/FallbackStrategyOptions.TResult.cs index 1f4e55420d4..687f4e85ac9 100644 --- a/src/Polly.Core/Fallback/FallbackStrategyOptions.TResult.cs +++ b/src/Polly.Core/Fallback/FallbackStrategyOptions.TResult.cs @@ -8,6 +8,11 @@ namespace Polly.Fallback; /// The result type. public class FallbackStrategyOptions : ResilienceStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public FallbackStrategyOptions() => Name = FallbackConstants.DefaultName; + /// /// Gets or sets the outcome predicate for determining whether a fallback should be executed. /// diff --git a/src/Polly.Core/Hedging/HedgingConstants.cs b/src/Polly.Core/Hedging/HedgingConstants.cs index adcd2134831..d6b1bb9f1d0 100644 --- a/src/Polly.Core/Hedging/HedgingConstants.cs +++ b/src/Polly.Core/Hedging/HedgingConstants.cs @@ -2,6 +2,8 @@ namespace Polly.Hedging; internal static class HedgingConstants { + public const string DefaultName = "Hedging"; + public const string OnHedgingEventName = "OnHedging"; public const int DefaultMaxHedgedAttempts = 2; diff --git a/src/Polly.Core/Hedging/HedgingStrategyOptions.TResult.cs b/src/Polly.Core/Hedging/HedgingStrategyOptions.TResult.cs index 49a543a604e..45d80b94ecc 100644 --- a/src/Polly.Core/Hedging/HedgingStrategyOptions.TResult.cs +++ b/src/Polly.Core/Hedging/HedgingStrategyOptions.TResult.cs @@ -8,6 +8,11 @@ namespace Polly.Hedging; /// The type of result these hedging options handle. public class HedgingStrategyOptions : ResilienceStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public HedgingStrategyOptions() => Name = HedgingConstants.DefaultName; + /// /// Gets or sets the minimal time of waiting before spawning a new hedged call. /// diff --git a/src/Polly.Core/Retry/RetryConstants.cs b/src/Polly.Core/Retry/RetryConstants.cs index d45a3d12ed8..a4da3a579b3 100644 --- a/src/Polly.Core/Retry/RetryConstants.cs +++ b/src/Polly.Core/Retry/RetryConstants.cs @@ -2,6 +2,8 @@ namespace Polly.Retry; internal static class RetryConstants { + public const string DefaultName = "Retry"; + public const string OnRetryEvent = "OnRetry"; public const RetryBackoffType DefaultBackoffType = RetryBackoffType.Constant; diff --git a/src/Polly.Core/Retry/RetryStrategyOptions.TResult.cs b/src/Polly.Core/Retry/RetryStrategyOptions.TResult.cs index fdd678d3f50..ad8cdd19f88 100644 --- a/src/Polly.Core/Retry/RetryStrategyOptions.TResult.cs +++ b/src/Polly.Core/Retry/RetryStrategyOptions.TResult.cs @@ -8,6 +8,11 @@ namespace Polly.Retry; /// The type of result the retry strategy handles. public class RetryStrategyOptions : ResilienceStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public RetryStrategyOptions() => Name = RetryConstants.DefaultName; + /// /// Gets or sets the maximum number of retries to use, in addition to the original call. /// diff --git a/src/Polly.Core/Timeout/TimeoutConstants.cs b/src/Polly.Core/Timeout/TimeoutConstants.cs index 097c654827d..fa6437721b1 100644 --- a/src/Polly.Core/Timeout/TimeoutConstants.cs +++ b/src/Polly.Core/Timeout/TimeoutConstants.cs @@ -2,5 +2,7 @@ namespace Polly.Timeout; internal static class TimeoutConstants { + public const string DefaultName = "Timeout"; + public const string OnTimeoutEvent = "OnTimeout"; } diff --git a/src/Polly.Core/Timeout/TimeoutStrategyOptions.cs b/src/Polly.Core/Timeout/TimeoutStrategyOptions.cs index 3b65b478efa..3edcc597a87 100644 --- a/src/Polly.Core/Timeout/TimeoutStrategyOptions.cs +++ b/src/Polly.Core/Timeout/TimeoutStrategyOptions.cs @@ -7,6 +7,11 @@ namespace Polly.Timeout; /// public class TimeoutStrategyOptions : ResilienceStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public TimeoutStrategyOptions() => Name = TimeoutConstants.DefaultName; + #pragma warning disable IL2026 // Addressed with DynamicDependency on ValidationHelper.Validate method /// /// Gets or sets the default timeout. diff --git a/src/Polly.RateLimiting/RateLimiterConstants.cs b/src/Polly.RateLimiting/RateLimiterConstants.cs index f56eb43f674..5b0c205f48b 100644 --- a/src/Polly.RateLimiting/RateLimiterConstants.cs +++ b/src/Polly.RateLimiting/RateLimiterConstants.cs @@ -2,6 +2,8 @@ namespace Polly.RateLimiting; internal static class RateLimiterConstants { + public const string DefaultName = "RateLimiter"; + public const int DefaultPermitLimit = 1000; public const int DefaultQueueLimit = 0; diff --git a/src/Polly.RateLimiting/RateLimiterStrategyOptions.cs b/src/Polly.RateLimiting/RateLimiterStrategyOptions.cs index 1eac041ee44..e64ffb49702 100644 --- a/src/Polly.RateLimiting/RateLimiterStrategyOptions.cs +++ b/src/Polly.RateLimiting/RateLimiterStrategyOptions.cs @@ -8,6 +8,11 @@ namespace Polly.RateLimiting; /// public class RateLimiterStrategyOptions : ResilienceStrategyOptions { + /// + /// Initializes a new instance of the class. + /// + public RateLimiterStrategyOptions() => Name = RateLimiterConstants.DefaultName; + /// /// Gets or sets the default rate limiter options. /// diff --git a/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerOptionsTests.cs b/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerOptionsTests.cs index 6473dbacf95..10a8127d807 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerOptionsTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerOptionsTests.cs @@ -6,29 +6,6 @@ namespace Polly.Core.Tests.CircuitBreaker; public class CircuitBreakerOptionsTests { - [Fact] - public void Ctor_Defaults() - { - var options = new CircuitBreakerStrategyOptions(); - options.BreakDuration.Should().Be(TimeSpan.FromSeconds(5)); - options.FailureRatio.Should().Be(0.1); - options.MinimumThroughput.Should().Be(100); - options.SamplingDuration.Should().Be(TimeSpan.FromSeconds(30)); - options.OnOpened.Should().BeNull(); - options.OnClosed.Should().BeNull(); - options.OnHalfOpened.Should().BeNull(); - options.ShouldHandle.Should().NotBeNull(); - options.Name.Should().BeNull(); - - // now set to min values - options.FailureRatio = 0.001; - options.BreakDuration = TimeSpan.FromMilliseconds(500); - options.MinimumThroughput = 2; - options.SamplingDuration = TimeSpan.FromMilliseconds(500); - - ValidationHelper.ValidateObject(new(options, "Dummy.")); - } - [Fact] public async Task ShouldHandle_EnsureDefaults() { @@ -42,7 +19,7 @@ public async Task ShouldHandle_EnsureDefaults() } [Fact] - public void Ctor_Generic_Defaults() + public void Ctor_Defaults() { var options = new CircuitBreakerStrategyOptions(); @@ -54,7 +31,7 @@ public void Ctor_Generic_Defaults() options.OnClosed.Should().BeNull(); options.OnHalfOpened.Should().BeNull(); options.ShouldHandle.Should().NotBeNull(); - options.Name.Should().BeNull(); + options.Name.Should().Be("CircuitBreaker"); // now set to min values options.FailureRatio = 0.001; diff --git a/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs b/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs index 430e03abce9..5417bae9c95 100644 --- a/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs @@ -14,6 +14,7 @@ public void Ctor_EnsureDefaults() options.ShouldHandle.Should().NotBeNull(); options.OnFallback.Should().BeNull(); options.FallbackAction.Should().BeNull(); + options.Name.Should().Be("Fallback"); } [Fact] diff --git a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs index cdf470a53ba..4d2a55e72ff 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs @@ -16,6 +16,7 @@ public void Ctor_EnsureDefaults() options.HedgingDelay.Should().Be(TimeSpan.FromSeconds(2)); options.MaxHedgedAttempts.Should().Be(2); options.OnHedging.Should().BeNull(); + options.Name.Should().Be("Hedging"); } [InlineData(true)] diff --git a/test/Polly.Core.Tests/Retry/RetryStrategyOptionsTests.cs b/test/Polly.Core.Tests/Retry/RetryStrategyOptionsTests.cs index f7d8c47e060..85be2996f9b 100644 --- a/test/Polly.Core.Tests/Retry/RetryStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Retry/RetryStrategyOptionsTests.cs @@ -20,6 +20,7 @@ public void Ctor_Ok() options.RetryCount.Should().Be(3); options.BackoffType.Should().Be(RetryBackoffType.Constant); options.BaseDelay.Should().Be(TimeSpan.FromSeconds(2)); + options.Name.Should().Be("Retry"); } [Fact] diff --git a/test/Polly.Core.Tests/Timeout/TimeoutStrategyOptionsTests.cs b/test/Polly.Core.Tests/Timeout/TimeoutStrategyOptionsTests.cs index 9a83f874218..c825b76a272 100644 --- a/test/Polly.Core.Tests/Timeout/TimeoutStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Timeout/TimeoutStrategyOptionsTests.cs @@ -13,6 +13,7 @@ public void Ctor_EnsureDefaultValues() options.TimeoutGenerator.Should().BeNull(); options.OnTimeout.Should().BeNull(); + options.Name.Should().Be("Timeout"); } [MemberData(nameof(TimeoutTestUtils.InvalidTimeouts), MemberType = typeof(TimeoutTestUtils))] diff --git a/test/Polly.RateLimiting.Tests/RateLimiterStrategyOptionsTests.cs b/test/Polly.RateLimiting.Tests/RateLimiterStrategyOptionsTests.cs index cfdb9782271..23fba9dc63c 100644 --- a/test/Polly.RateLimiting.Tests/RateLimiterStrategyOptionsTests.cs +++ b/test/Polly.RateLimiting.Tests/RateLimiterStrategyOptionsTests.cs @@ -11,5 +11,6 @@ public void Ctor_EnsureDefaults() options.OnRejected.Should().BeNull(); options.DefaultRateLimiterOptions.PermitLimit.Should().Be(1000); options.DefaultRateLimiterOptions.QueueLimit.Should().Be(0); + options.Name.Should().Be("RateLimiter"); } }