コード例 #1
0
        public void LinearRetryOnException_NoException_NoRetry()
        {
            var retryCounter = -1;

            var retryService = new TimeoutLinearRetryOnExceptionService(times: 3, delay: TimeSpan.FromMilliseconds(100));

            retryService.Execute((token) =>
            {
                retryCounter++;
            },
                                 CancellationToken.None);

            retryCounter.Should().Be(0);
        }
コード例 #2
0
        public void LinearRetryOnException_OneTimeoutException_SuccessWithOneRetry()
        {
            var retryCounter     = 0;
            var exceptionCounter = 0;

            var retryService = new TimeoutLinearRetryOnExceptionService(times: 3, delay: TimeSpan.FromMilliseconds(100));

            retryService.Execute((token) =>
            {
                if (retryCounter == 0) // throws TimeoutException on the first action call
                {
                    retryCounter++;
                    exceptionCounter++;

                    throw new TimeoutException("Timeout action!");
                }
            },
                                 CancellationToken.None);
        }
コード例 #3
0
        public void LinearRetryOnException_UnmanagedExceptions_ThrowsException()
        {
            var exceptionCounter = 0;

            Action throws = () =>
            {
                var retryService = new TimeoutLinearRetryOnExceptionService(times: 3, delay: TimeSpan.FromMilliseconds(100));

                retryService.Execute((token) =>
                {
                    exceptionCounter++;

                    throw new OperationCanceledException("Operation canceled action!");
                },
                                     CancellationToken.None);
            };

            throws.Should().Throw <OperationCanceledException>();
            exceptionCounter.Should().Be(1);
        }
コード例 #4
0
        public void LinearRetryOnException_ManyTimeoutExceptions_SuccessWithManyRetries()
        {
            var retryCounter     = 0;
            var exceptionCounter = 0;

            var retryService = new TimeoutLinearRetryOnExceptionService(times: 3, delay: TimeSpan.FromMilliseconds(100));

            retryService.Execute((token) =>
            {
                if (retryCounter == 0 || retryCounter == 1) // throws TimeoutException on the first and second action calls
                {
                    retryCounter++;
                    exceptionCounter++;

                    throw new TimeoutException("Timeout action!");
                }
            },
                                 CancellationToken.None);

            exceptionCounter.Should().Be(2);
            retryCounter.Should().Be(2);
        }