public void TestLinearRetry()
        {
            IReconnectRetryPolicy linearRetry = new LinearRetry(5000);

            Assert.False(linearRetry.ShouldRetry(0, 0));
            Assert.False(linearRetry.ShouldRetry(2, 4999));
            Assert.True(linearRetry.ShouldRetry(1, 5000));
        }
Example #2
0
        public void ShouldRetry_ShouldReturn_LinearRetryInterval(uint currentRetryCount, int expectedRetryInterval)
        {
            var retry = new LinearRetry(TimeSpan.FromSeconds(4), 3);

            retry.ShouldRetry(currentRetryCount, HttpStatusCode.RequestTimeout, out var retryInterval);

            Assert.Equal(expectedRetryInterval, retryInterval.Seconds);
        }
        public void VerifyLinearRetryBackOffTime()
        {
            OperationContext opContext = new OperationContext();
            TimeSpan         retryInterval;

            IRetryPolicy retryPolicy = new LinearRetry(TimeSpan.FromSeconds(10), 4);

            Assert.IsTrue(retryPolicy.ShouldRetry(0, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval);

            Assert.IsTrue(retryPolicy.ShouldRetry(1, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval);

            Assert.IsTrue(retryPolicy.ShouldRetry(2, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval);

            Assert.IsTrue(retryPolicy.ShouldRetry(3, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval);

            Assert.IsFalse(retryPolicy.ShouldRetry(4, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(10), retryInterval);

            retryPolicy = new LinearRetry();

            Assert.IsTrue(retryPolicy.ShouldRetry(0, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval);

            Assert.IsTrue(retryPolicy.ShouldRetry(1, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval);

            Assert.IsTrue(retryPolicy.ShouldRetry(2, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval);

            Assert.IsFalse(retryPolicy.ShouldRetry(3, 503, new Exception(), out retryInterval, opContext));
            Assert.AreEqual(TimeSpan.FromSeconds(30), retryInterval);
        }
Example #4
0
        public void ShouldRetry_ShouldReturn_IfRetryCountIsTooHigh(uint currentRetryCount, bool expectedResult)
        {
            var retry = new LinearRetry(default(TimeSpan), 3);

            Assert.Equal(expectedResult, retry.ShouldRetry(currentRetryCount, HttpStatusCode.RequestTimeout, out _));
        }
Example #5
0
        public void ShouldRetry_ShouldReturnFalse_OnNonRetriableStatusCodes(HttpStatusCode httpStatusCode, bool expectedRetryResult)
        {
            var retry = new LinearRetry();

            Assert.Equal(expectedRetryResult, retry.ShouldRetry(0, httpStatusCode, out _));
        }