public void Should_return_specified_retry_count()
        {
            var retryCount     = 10;
            var recoveryPolicy = RecoveryPolicyFactory.LinearBackoff(TimeSpan.FromSeconds(1), retryCount);

            Assert.Equal(retryCount, recoveryPolicy.RetryCount);
        }
        public void Should_throw_exception_when_retry_count_less_than_zero()
        {
            var initialDelay = TimeSpan.FromMilliseconds(10);
            var retryCount   = -1;

            Assert.Throws <ArgumentOutOfRangeException>(() => RecoveryPolicyFactory.LinearBackoff(initialDelay, retryCount: retryCount));
        }
        public void Should_throw_exception_when_max_delay_less_than_initial_delay()
        {
            var initialDelay = TimeSpan.FromMilliseconds(10);
            var maxDelay     = TimeSpan.FromMilliseconds(9);

            Assert.Throws <ArgumentOutOfRangeException>(() => RecoveryPolicyFactory.LinearBackoff(initialDelay, maxDelay));
        }
        public void Should_return_delays_in_a_linear_manner(double initialDelayMilliseconds, double factor, double[] delays)
        {
            var initialDelay   = TimeSpan.FromMilliseconds(initialDelayMilliseconds);
            var recoveryPolicy = RecoveryPolicyFactory.LinearBackoff(initialDelay, factor: factor);
            var result         = RecoveryPolicyUtils.GetDelays(recoveryPolicy);

            Assert.Equal(delays, result);
        }
        public void Should_return_constant_delay_when_factor_is_zero_and_fast_first_flag_enabled()
        {
            var initialDelay   = TimeSpan.FromMilliseconds(10);
            var factor         = 0;
            var recoveryPolicy = RecoveryPolicyFactory.LinearBackoff(initialDelay, factor: factor, fastFirst: true);
            var result         = RecoveryPolicyUtils.GetDelays(recoveryPolicy);

            Assert.Equal(new double[] { 0, 10, 10, 10, 10 }, result);
        }
        public void Should_not_return_delay_longer_than_specified_max_delay()
        {
            var initialDelay   = TimeSpan.FromMilliseconds(10);
            var maxDelay       = TimeSpan.FromMilliseconds(90);
            var factor         = 3;
            var recoveryPolicy = RecoveryPolicyFactory.LinearBackoff(initialDelay, maxDelay, factor: factor);
            var result         = RecoveryPolicyUtils.GetDelays(recoveryPolicy);

            Assert.Equal(new double[] { 10, 40, 70, 90, 90 }, result);
        }
        public void Should_return_no_limit_retry_count_when_no_retry_count_specified()
        {
            var recoveryPolicy = RecoveryPolicyFactory.LinearBackoff(TimeSpan.FromSeconds(1));

            Assert.Equal(int.MaxValue, recoveryPolicy.RetryCount);
        }