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); } }
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); } }
public void RunAsync_RetryStrategyProvidesNegativeTimeSpan_ThrowsException() { // Arrange var retry = new RetryImpl((() => Throws())); retry.Using(new ReturnNegativeTimeSpanRetryStrategy()); // Act retry.RunAsync().Wait(); // Assert // Expected exception }
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); }
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); } }
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); }