public void ExponentialBackoffDoesNotUnderflow() { var exponentialBackoff = new ExponentialBackoffRetryStrategy( MAX_RETRY_ATTEMPTS, RetryStrategy.DefaultMinBackoff, RetryStrategy.DefaultMaxBackoff, RetryStrategy.DefaultClientBackoff); ShouldRetry shouldRetry = exponentialBackoff.GetShouldRetry(); for (int i = 1; i < MAX_RETRY_ATTEMPTS; i++) { shouldRetry(i, new Exception(), out TimeSpan delay); if (delay.TotalSeconds <= 0) { Assert.Fail("Exponential backoff should never recommend a negative delay"); } } }
/// <summary> /// Returns true if, based on the parameters, the operation should be retried. /// </summary> /// <param name="currentRetryCount">How many times the operation has been retried.</param> /// <param name="lastException">Operation exception.</param> /// <param name="retryInterval">Next retry should be performed after this time interval.</param> /// <returns>True if the operation should be retried, false otherwise.</returns> public bool ShouldRetry(int currentRetryCount, Exception lastException, out TimeSpan retryInterval) { return(_exponentialBackoffRetryStrategy.GetShouldRetry()(currentRetryCount, lastException, out retryInterval)); }