Пример #1
0
        public async Task ExecutionWithoutRetry()
        {
            RetryHandler retryHandler = new RetryHandler(5, 15, 7, false);

            retryHandler
            .ExcludeForRetry <NullReferenceException>();

            short retryCount = -1;
            short errorCount = 0;

            await retryHandler.ExecuteAsync(async() =>
            {
                retryCount++;

                await Task.Delay(20);

                throw new NullReferenceException();
            },
                                            async (exception, retryIndex, retryLimit) =>
            {
                errorCount++;

                await Task.Delay(10);

                Assert.NotNull(exception);
                Assert.Equal(0, retryIndex);
                Assert.Equal(0, retryLimit);
            });

            Assert.Equal(0, retryCount);
            Assert.Equal(1, errorCount);
        }
Пример #2
0
        public void ExceptionExclusion()
        {
            RetryHandler retryHandler = new RetryHandler(5, 15, 7, false);

            retryHandler
            .ExcludeForRetry <TimeoutException>()
            .ExcludeForRetry <NullReferenceException>();

            Assert.False(retryHandler.IsForRetry(new TimeoutException()));
            Assert.False(retryHandler.IsForRetry(new NullReferenceException()));
            Assert.True(retryHandler.IsForRetry(new ArgumentNullException()));
        }