public void Function_Should_Be_A_Success() { var exceptionCount = 0; var failureCount = 0; var successCount = 0; var watch = new Stopwatch(); watch.Start(); RetryLogic .Do <int>(this.NoException) .Handle <FileNotFoundException>() .AtMost(3) .WithConstantInterval(TimeSpan.FromMilliseconds(2000)) .OnException <FileNotFoundException>(e => ++ exceptionCount) .OnFailure(() => ++ failureCount) .OnSuccess(x => { ++successCount; }) .Run(); watch.Stop(); exceptionCount.ShouldEqual(0); failureCount.ShouldEqual(0); successCount.ShouldEqual(1); }
public void Function_Should_Be_Tried_3Times_With_ExponentialInterval() { var exceptionCount = 0; var failureCount = 0; var successCount = 0; var watch = new Stopwatch(); watch.Start(); RetryLogic .Do <int>(this.ThrowException) .Handle <FileNotFoundException>() .AtMost(4) .WithExponentialInterval(TimeSpan.FromMilliseconds(2000), 2) .OnException <FileNotFoundException>(e => ++ exceptionCount) .OnFailure(() => ++ failureCount) .OnSuccess(x => { ++successCount; }) .Run(); watch.Stop(); watch.Elapsed.ShouldBeGreaterThanOrEqualTo(TimeSpan.FromMilliseconds(12000)); exceptionCount.ShouldEqual(4); failureCount.ShouldEqual(1); successCount.ShouldEqual(0); }