public async Task TestTryUntilWithTryIntervalAsync() { var times = 5; var generator = new Generator(times); bool result = false; Assert.That(await RetryHelperTest.MeasureTime(async() => result = await _target.Try(() => generator.NextAsync()).WithTryInterval(RetryHelperTest.Interval * 2).Until(t => t)), Is.EqualTo(RetryHelperTest.Interval * 2 * times).Within(RetryHelperTest.Tolerance)); Assert.That(result, Is.True); }
public void TestTryUntilWithMaxTryCount() { var times = 5; var generator = new Generator(times); bool result = false; Assert.That(RetryHelperTest.MeasureTime(() => result = _target.Try(() => generator.Next()).WithMaxTryCount(times + 1).Until(t => t)), Is.EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Assert.That(result, Is.True); }
public void TestTryUntilWithTryInterval() { var times = 5; var generator = new Generator(times); bool result = false; Expect(RetryHelperTest.CountTime(() => result = _target.Try(() => generator.Next()).WithTryInterval(RetryHelperTest.Interval * 2).Until(t => t)), EqualTo(RetryHelperTest.Interval * 2 * times).Within(RetryHelperTest.Tolerance)); Expect(result, True); }
public void TestTryUntilSuccessFirstTime() { var times = 0; var generator = new Generator(times); bool result = false; Expect(RetryHelperTest.CountTime(() => result = _target.Try(() => generator.Next()).Until(t => t)), EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Expect(generator.TriedTimes, EqualTo(times + 1)); Expect(result, True); }
public void TestTryUntilWithMaxTryCountExceededAsync() { var times = 5; var generator = new Generator(times); bool result = false; Assert.That(RetryHelperTest.MeasureTime(() => Assert.ThrowsAsync <TimeoutException>(async() => result = await _target.Try(async() => await generator.NextAsync()).WithMaxTryCount(times).Until(t => t))), Is.EqualTo(RetryHelperTest.Interval * (times - 1)).Within(RetryHelperTest.Tolerance)); Assert.That(result, Is.False); }
public void TestTryUntilNoExceptionOfTypeAfterFiveTimes() { var times = 10; var generator = new Generator(times, true); bool result = false; Expect(RetryHelperTest.CountTime(() => result = _target.Try(() => generator.Next()).UntilNoException <ApplicationException>()), EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Expect(generator.TriedTimes, EqualTo(times + 1)); Expect(result, True); }
public async Task TestTryUntilNoExceptionOfTypePassedAsParameterAfterFiveTimesAsync() { var times = 10; var generator = new Generator(times, true); bool result = false; Assert.That(await RetryHelperTest.MeasureTime(async() => result = await _target.Try(() => generator.NextAsync()).UntilNoException(typeof(ApplicationException))), Is.EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.AsyncTolerance)); Assert.That(generator.TriedTimes, Is.EqualTo(times + 1)); Assert.That(result, Is.True); }
public async Task TestTryUntilNoExceptionSuccessFirstTimeAsync() { var times = 0; var generator = new Generator(times); bool result = false; Assert.That(await RetryHelperTest.MeasureTime(async() => result = await _target.Try(async() => await generator.NextAsync()).Until(t => t)), Is.EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.AsyncTolerance)); Assert.That(generator.TriedTimes, Is.EqualTo(times + 1)); Assert.That(result, Is.True); }
public void TestTryUntilNoExceptionSuccessFirstTime() { var times = 0; var generator = new Generator(times); bool result = false; Assert.That(RetryHelperTest.MeasureTime(() => result = _target.Try(() => generator.Next()).Until(t => t)), Is.EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Assert.That(generator.TriedTimes, Is.EqualTo(times + 1)); Assert.That(result, Is.True); }
public void TestTryUntilWithMaxTryCountExceeded() { var times = 5; var generator = new Generator(times); bool result = false; Expect(RetryHelperTest.CountTime(() => Expect(() => result = _target.Try(() => generator.Next()).WithMaxTryCount(times).Until(t => t), Throws.TypeOf <TimeoutException>())), EqualTo(RetryHelperTest.Interval * (times - 1)).Within(RetryHelperTest.Tolerance)); Expect(result, False); }
public async Task TestTryUntilNoExceptionAfterFiveTimesAsync() { var times = 10; var generator = new Generator(times, true); generator.RandomExceptionType = true; bool result = false; Assert.That(await RetryHelperTest.MeasureTime(async() => result = await _target.Try(async() => await generator.NextAsync()).UntilNoException()), Is.EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.AsyncTolerance)); Assert.That(generator.TriedTimes, Is.EqualTo(times + 1)); Assert.That(result, Is.True); }
public async Task TestTryAsyncUntilAfterFiveTimesAsync() { var times = 5; var generator = new Generator(times); bool result = false; Assert.That( await RetryHelperTest.MeasureTime(async() => result = await _target .TryAsync(() => generator.Next()) .Until(t => t)), Is.EqualTo(RetryHelperTest.Interval * times).Within(RetryHelperTest.Tolerance)); Assert.That(generator.TriedTimes, Is.EqualTo(times + 1)); Assert.That(result, Is.True); }