Example #1
0
        public Task MaxAttemptsRespected()
        {
            var settings = RetrySettings.FromConstantBackoff(
                maxAttempts: 4, backoff: OneSecond, retryFilter: ex => true, backoffJitter: RetrySettings.NoJitter);
            var scheduler = new FakeScheduler();

            var sequence = RetryAttempt.CreateRetrySequence(settings, scheduler);

            // Should attempt at T=0, T=1, T=2, T=3, then stop because we're only allowed four attempts.
            return(AssertAttemptsAsync(sequence, scheduler, () => new Exception(), 0, 1, 2, 3));
        }
Example #2
0
        public Task InitialBackoffOverrideRespected()
        {
            var settings = RetrySettings.FromConstantBackoff(
                maxAttempts: 4, backoff: FiveSeconds, retryFilter: ex => true, backoffJitter: RetrySettings.NoJitter);
            var scheduler = new FakeScheduler();

            var sequence = RetryAttempt.CreateRetrySequence(settings, scheduler, initialBackoffOverride: OneSecond);

            // Should attempt at T=0, T=1, T=6, T=11.
            return(AssertAttemptsAsync(sequence, scheduler, () => new Exception(), 0, 1, 6, 11));
        }
        public void FromConstantBackoff_DefaultJitter()
        {
            var backoff  = TimeSpan.FromSeconds(3);
            var filter   = RetrySettings.FilterForStatusCodes(StatusCode.Aborted);
            var settings = RetrySettings.FromConstantBackoff(10, backoff, filter);

            Assert.Equal(10, settings.MaxAttempts);
            Assert.Equal(backoff, settings.InitialBackoff);
            Assert.Equal(backoff, settings.MaxBackoff);
            Assert.Same(filter, settings.RetryFilter);
            Assert.Same(RetrySettings.RandomJitter, settings.BackoffJitter);
        }