Esempio n. 1
0
        public void Run_ActionSucceedsThirdTime_ThreadSleepCalledTwoTimes()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var sleepInvokeCounter = 0;
                var callCount          = 0;
                ShimThread.SleepInt32 = i => sleepInvokeCounter += 1;
                var retry = new RetryImpl(() =>
                {
                    callCount += 1;
                    if (callCount == 3)
                    {
                        return;
                    }
                    Throws();
                });

                // Act
                retry.Using(new ConstantWaitTimeRetryStrategy
                {
                    RetryDelay = TimeSpan.FromMilliseconds(1337)
                })
                .Run();

                // Assert
                Assert.AreEqual(2, sleepInvokeCounter);
            }
        }
Esempio n. 2
0
        public void Using_ActionFails_TaskDelayCalledWithCorrectValue()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var argumentPassedToTaskDelay = new TimeSpan();
                ShimTask.DelayTimeSpanCancellationToken = (t, c) =>
                {
                    argumentPassedToTaskDelay = t;
                    return(Task.CompletedTask);
                };
                var retry = new RetryImpl(() => Throws());

                // Act
                retry.Using(new ConstantWaitTimeRetryStrategy
                {
                    RetryDelay = TimeSpan.FromMilliseconds(1337)
                })
                .MaximumNumberOfTries(2)
                .RunAsync().Wait();

                // Assert
                Assert.AreEqual(TimeSpan.FromMilliseconds(1337), argumentPassedToTaskDelay);
            }
        }
Esempio n. 3
0
        public void RunAsync_RetryStrategyProvidesNegativeTimeSpan_ThrowsException()
        {
            // Arrange
            var retry = new RetryImpl((() => Throws()));

            retry.Using(new ReturnNegativeTimeSpanRetryStrategy());

            // Act
            retry.RunAsync().Wait();

            // Assert
            // Expected exception
        }
Esempio n. 4
0
        public void Using_ActionFails_TaskDelayCalledWithCorrectValue()
        {
            // Arrange
            var retry = new RetryImpl(() => Throws(), new RetryAllExceptionBehavior(), doNotWaitHandler);

            // Act
            retry.Using(new ConstantWaitTimeRetryStrategy
            {
                RetryDelay = TimeSpan.FromMilliseconds(1337)
            })
            .MaximumNumberOfTries(2)
            .RunAsync().Wait();

            // Assert
            Assert.AreEqual(TimeSpan.FromMilliseconds(1337), doNotWaitHandler.LastSleepAmount);
        }
Esempio n. 5
0
        public void Using_ActionFails_ThreadSleepCalledWithCorrectValue()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                var argumentPassedToSleep = 0;
                ShimThread.SleepInt32 = i => argumentPassedToSleep = i;
                var retry = new RetryImpl(() => Throws());

                // Act
                retry.Using(new ConstantWaitTimeRetryStrategy
                {
                    RetryDelay = TimeSpan.FromMilliseconds(1337)
                })
                .MaximumNumberOfTries(2)
                .Run();

                // Assert
                Assert.AreEqual(1337, argumentPassedToSleep);
            }
        }
Esempio n. 6
0
        public void Run_ActionSucceedsThirdTime_ThreadSleepCalledTwoTimes()
        {
            // Arrange
            var callCount = 0;
            var retry     = new RetryImpl(() =>
            {
                callCount += 1;
                if (callCount == 3)
                {
                    return;
                }
                Throws();
            }, new RetryAllExceptionBehavior(), doNotWaitHandler);

            // Act
            retry.Using(new ConstantWaitTimeRetryStrategy
            {
                RetryDelay = TimeSpan.FromMilliseconds(1337)
            }).Run();

            // Assert
            Assert.AreEqual(2, doNotWaitHandler.SleepCount);
        }