public void Should_Fail_Initital_Attempt_And_Each_Explictely_Specified_Backoff_Retry(int maxAttempts) { Action failingFunction = () => throw new Exception("function failed"); var backoffRetry = new BackoffRetry(failingFunction); bool result = backoffRetry.AttemptExponential(maxAttempts, TimeSpan.FromMilliseconds(10)); Assert.That(result, Is.False); Assert.That(backoffRetry.Attempts, Is.EqualTo(maxAttempts)); Assert.That(backoffRetry.Exceptions.Count(), Is.EqualTo(maxAttempts)); }
public void Should_Suceed_On_First_Attempt() { Action successfulFunction = () => { Thread.Sleep(10); }; var backoffRetry = new BackoffRetry(successfulFunction); bool result = backoffRetry.AttemptExponential(10, TimeSpan.FromMilliseconds(10)); Assert.That(result, Is.True); Assert.That(backoffRetry.Attempts, Is.EqualTo(1)); Assert.That(backoffRetry.Exceptions.Count(), Is.EqualTo(0)); }
public void Should_Succeed_After_Specified_Attempt(int succeedOnAttempt) { int attempt = 1; Action successfulFunction = () => { if (attempt++ < succeedOnAttempt) { throw new Exception("Not time to succeed yet"); } }; var backoffRetry = new BackoffRetry(successfulFunction); bool result = backoffRetry.AttemptExponential(10, TimeSpan.FromMilliseconds(10)); Assert.That(result, Is.True); Assert.That(backoffRetry.Attempts, Is.EqualTo(succeedOnAttempt)); Assert.That(backoffRetry.Exceptions.Count(), Is.EqualTo(succeedOnAttempt - 1)); }
public void Should_Throw_ArgumentOutOfRangeException_When_Requesting_Only_One_Attempt() { var backoffRetry = new BackoffRetry(() => { }); Assert.Throws(typeof(ArgumentOutOfRangeException), () => backoffRetry.AttemptExponential(1, TimeSpan.FromMilliseconds(10))); }