Ejemplo n.º 1
0
        public void FactorRetryOnException_NoException_NoRetry()
        {
            var retryCounter = -1;

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

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

            retryCounter.Should().Be(0);
        }
Ejemplo n.º 2
0
        public void FactorRetryOnException_OneTimeoutException_SuccessWithOneRetry()
        {
            var retryCounter     = 0;
            var exceptionCounter = 0;

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

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

                    throw new TimeoutException("Timeout action!");
                }
            },
                                 CancellationToken.None);
        }
Ejemplo n.º 3
0
        public void FactorRetryOnException_UnmanagedExceptions_ThrowsException()
        {
            var exceptionCounter = 0;

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

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

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

            throws.Should().Throw <OperationCanceledException>();
            exceptionCounter.Should().Be(1);
        }
Ejemplo n.º 4
0
        public void FactorRetryOnException_ManyTimeoutExceptions_SuccessWithManyRetries()
        {
            var retryCounter     = 0;
            var exceptionCounter = 0;

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

            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);
        }