Esempio n. 1
0
        public void ShouldRetry_RequestNull_NotRetry()
        {
            var maxNumberRetries           = 2;
            var retryStrategy              = new DefaultRetryStrategy(maxNumberRetries);
            HttpRequestMessage httpRequest = null;
            var httpResponse      = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            var hadRetryableError = false;
            var numberRetries     = 0;

            RetryResponse retryResponse = retryStrategy.ShouldRetry(
                httpRequest, httpResponse, hadRetryableError, numberRetries);

            Assert.False(retryResponse.Retry);
            Assert.Equal(TimeSpan.Zero.Ticks, retryResponse.Delay.Ticks);
        }
Esempio n. 2
0
        public void ShouldRetry_MaxDelay_Retry()
        {
            var maxNumberRetries  = 5;
            var retryStrategy     = new DefaultRetryStrategy(maxNumberRetries);
            var httpRequest       = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/x");
            var httpResponse      = new HttpResponseMessage(HttpStatusCode.InternalServerError);
            var hadRetryableError = false;
            var numberRetries     = 4;

            RetryResponse retryResponse = retryStrategy.ShouldRetry(
                httpRequest, httpResponse, hadRetryableError, numberRetries);

            Assert.True(retryResponse.Retry);
            Assert.Equal(DefaultRetryStrategy.MaxDelay.Ticks, retryResponse.Delay.Ticks);
        }
Esempio n. 3
0
        public void ShouldRetry_RetryableRequestAndRetryableError_Retry()
        {
            var maxNumberRetries             = 2;
            var retryStrategy                = new DefaultRetryStrategy(maxNumberRetries);
            var httpRequest                  = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/x");
            HttpResponseMessage httpResponse = null;
            var hadRetryableError            = true;
            var numberRetry                  = 0;

            RetryResponse retryResponse = retryStrategy.ShouldRetry(
                httpRequest, httpResponse, hadRetryableError, numberRetry);

            Assert.True(retryResponse.Retry);
            Assert.Equal(DefaultRetryStrategy.MinDelay.Ticks, retryResponse.Delay.Ticks);
        }
Esempio n. 4
0
        public void ShouldRetry_NoRetryableErrorAndNotRetryableResponse_NotRetry()
        {
            var maxNumberRetries  = 2;
            var retryStrategy     = new DefaultRetryStrategy(maxNumberRetries);
            var httpRequest       = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/x");
            var httpResponse      = new HttpResponseMessage(HttpStatusCode.OK);
            var hadRetryableError = false;
            var numberRetries     = 0;

            RetryResponse retryResponse = retryStrategy.ShouldRetry(
                httpRequest, httpResponse, hadRetryableError, numberRetries);

            Assert.False(retryResponse.Retry);
            Assert.Equal(TimeSpan.Zero.Ticks, retryResponse.Delay.Ticks);
        }
Esempio n. 5
0
        public void ShouldRetry_PostWithIdempotencyKeyEmpty_NotRetry()
        {
            var maxNumberRetries = 2;
            var retryStrategy    = new DefaultRetryStrategy(maxNumberRetries);
            var httpRequest      = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8080/x");

            httpRequest.Headers.Add(Headers.IdempotencyKey, string.Empty);
            var httpResponse      = new HttpResponseMessage(HttpStatusCode.Conflict);
            var hadRetryableError = false;
            var numberRetries     = 1;

            RetryResponse retryResponse = retryStrategy.ShouldRetry(
                httpRequest, httpResponse, hadRetryableError, numberRetries);

            Assert.False(retryResponse.Retry);
            Assert.Equal(TimeSpan.Zero.Ticks, retryResponse.Delay.Ticks);
        }
Esempio n. 6
0
        public void ShouldRetry_PostWithIdempotencyKeyAndRetryableStatusCode_Retry()
        {
            var maxNumberRetries = 2;
            var retryStrategy    = new DefaultRetryStrategy(maxNumberRetries);
            var httpRequest      = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8080/x");

            httpRequest.Headers.Add(Headers.IdempotencyKey, Guid.NewGuid().ToString());
            var httpResponse      = new HttpResponseMessage(HttpStatusCode.Conflict);
            var hadRetryableError = false;
            var numberRetries     = 1;

            RetryResponse retryResponse = retryStrategy.ShouldRetry(
                httpRequest, httpResponse, hadRetryableError, numberRetries);

            Assert.True(retryResponse.Retry);
            Assert.Equal(
                2 * DefaultRetryStrategy.MinDelay.Ticks,
                retryResponse.Delay.Ticks);
        }