Пример #1
0
        public async Task Should_retry_6_times_for_two_threads_when_client_returns_503()
        {
            const int retryCount    = 3;
            var       retrySettings = RetryPolicySettings.Jitter(retryCount,
                                                                 medianFirstRetryDelay: TimeSpan.FromMilliseconds(50));
            var wrapper = Create.HttpClientWrapperWrapperBuilder
                          .WithStatusCode(HttpStatusCode.ServiceUnavailable)
                          .WithRetrySettings(retrySettings)
                          .Please();

            const int taskCount = 2;
            await Helper.InvokeMultipleHttpRequests(wrapper.Client, taskCount);

            Assert.AreEqual((retryCount + 1) * taskCount, wrapper.NumberOfCalls);
        }
        public async Task Should_separately_distribute_retry_attempts_for_multiple_tasks()
        {
            const int retryCount    = 3;
            var       retryAttempts = new Dictionary <string, List <TimeSpan> >();
            var       settings      = new ResiliencePoliciesSettings
            {
                RetryPolicySettings = RetryPolicySettings.Jitter(retryCount, TimeSpan.FromMilliseconds(50)),
                OnRetry             = BuildOnRetryAction(retryAttempts),
            };

            var wrapper = Create.HttpClientWrapperWrapperBuilder
                          .WithStatusCode(HttpStatusCode.ServiceUnavailable)
                          .WithResiliencePolicySettings(settings)
                          .Please();

            const int taskCount = 2;
            await Helper.InvokeMultipleHttpRequests(wrapper.Client, taskCount);

            CollectionAssert.AreNotEquivalent(retryAttempts.First().Value, retryAttempts.Last().Value);
        }