From b3831bd2f3fce7fc7d7bfe45ef90a93ffbef10e5 Mon Sep 17 00:00:00 2001 From: Dixin Date: Sat, 27 Jan 2024 06:36:11 -0800 Subject: [PATCH] Fix unit test failure. --- .../RetryStrategyOptions.cs | 72 ++++++++++++++++--- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/Source/TransientFaultHandling.Configuration.Core/RetryStrategyOptions.cs b/Source/TransientFaultHandling.Configuration.Core/RetryStrategyOptions.cs index c0e1aa2..98133c3 100644 --- a/Source/TransientFaultHandling.Configuration.Core/RetryStrategyOptions.cs +++ b/Source/TransientFaultHandling.Configuration.Core/RetryStrategyOptions.cs @@ -10,6 +10,10 @@ public abstract record RetryStrategyOptions(bool FastFirstRetry); /// public record FixedIntervalOptions(bool FastFirstRetry, int RetryCount, TimeSpan RetryInterval) : RetryStrategyOptions(FastFirstRetry) { + private readonly int retryCount; + + private readonly TimeSpan retryInterval; + /// /// Initializes a new instance of the record. /// @@ -20,12 +24,20 @@ public FixedIntervalOptions() : this(RetryStrategy.DefaultFirstFastRetry, defaul /// /// Gets or sets the retry count. /// - public int RetryCount { get; init; } = RetryCount.ThrowIfNegative(); + public int RetryCount + { + get => this.retryCount; + init => this.retryCount = value.ThrowIfNegative(); + } /// /// Gets the time interval between retries. /// - public TimeSpan RetryInterval { get; init; } = RetryInterval.ThrowIfNegative(); + public TimeSpan RetryInterval + { + get => this.retryInterval; + init => this.retryInterval = value.ThrowIfNegative(); + } } /// @@ -33,6 +45,12 @@ public FixedIntervalOptions() : this(RetryStrategy.DefaultFirstFastRetry, defaul /// public record IncrementalOptions(bool FastFirstRetry, int RetryCount, TimeSpan InitialInterval, TimeSpan Increment) : RetryStrategyOptions(FastFirstRetry) { + private readonly int retryCount; + + private readonly TimeSpan initialInterval; + + private readonly TimeSpan increment; + /// /// Initializes a new instance of the record. /// @@ -43,17 +61,29 @@ public IncrementalOptions() : this(RetryStrategy.DefaultFirstFastRetry, default, /// /// Gets the maximum number of retry attempts. /// - public int RetryCount { get; init; } = RetryCount.ThrowIfNegative(); + public int RetryCount + { + get => this.retryCount; + init => this.retryCount = value.ThrowIfNegative(); + } /// /// Gets the initial interval that will apply for the first retry. /// - public TimeSpan InitialInterval { get; init; } = InitialInterval.ThrowIfNegative(); + public TimeSpan InitialInterval + { + get => this.initialInterval; + init => this.initialInterval = value.ThrowIfNegative(); + } /// /// Gets the incremental time value that will be used to calculate the progressive delay between retries.. /// - public TimeSpan Increment { get; init; } = Increment.ThrowIfNegative(); + public TimeSpan Increment + { + get => this.increment; + init => this.increment = value.ThrowIfNegative(); + } } /// @@ -61,6 +91,14 @@ public IncrementalOptions() : this(RetryStrategy.DefaultFirstFastRetry, default, /// public record ExponentialBackoffOptions(bool FastFirstRetry, int RetryCount, TimeSpan MinBackOff, TimeSpan MaxBackOff, TimeSpan DeltaBackOff) : RetryStrategyOptions(FastFirstRetry) { + private readonly int retryCount; + + private readonly TimeSpan minBackOff; + + private readonly TimeSpan maxBackOff; + + private readonly TimeSpan deltaBackOff; + /// /// Initializes a new instance of the record. /// @@ -71,20 +109,36 @@ public ExponentialBackoffOptions() : this(RetryStrategy.DefaultFirstFastRetry, d /// /// Gets the maximum number of retry attempts. /// - public int RetryCount { get; init; } = RetryCount.ThrowIfNegative(); + public int RetryCount + { + get => this.retryCount; + init => this.retryCount = value.ThrowIfNegative(); + } /// /// Gets the minimum backoff time. /// - public TimeSpan MinBackOff { get; init; } = MinBackOff.ThrowIfNegative(); + public TimeSpan MinBackOff + { + get => this.minBackOff; + init => this.minBackOff = value.ThrowIfNegative(); + } /// /// Gets the maximum backoff time. /// - public TimeSpan MaxBackOff { get; init; } = MaxBackOff.ThrowIfNegative(); + public TimeSpan MaxBackOff + { + get => this.maxBackOff; + init => this.maxBackOff = value.ThrowIfNegative(); + } /// /// Gets the value that will be used to calculate a random delta in the exponential delay between retries. /// - public TimeSpan DeltaBackOff { get; init; } = DeltaBackOff.ThrowIfNegative(); + public TimeSpan DeltaBackOff + { + get => this.deltaBackOff; + init => this.deltaBackOff = value.ThrowIfNegative(); + } } \ No newline at end of file