public void WaitAndRetry_WithAction() { TimeSpan slept = TimeSpan.Zero; SystemUtil.SetSleep(span => slept += span); int count = 0; var policy = ActionPolicy .Handle <TimeoutException>() .WaitAndRetry(Range.Create(5, i => i.Seconds()), (ex, s) => count += 1); // non-handled Expect <ArgumentException>(() => policy.Do(RaiseArgument)); Assert.AreEqual(TimeSpan.Zero, slept); Assert.AreEqual(0, count); // handled succeeds Raise <TimeoutException>(5, policy); Assert.AreEqual(10.Seconds(), slept); Assert.AreEqual(5, count); // handled fails Expect <TimeoutException>(6, policy); Assert.AreEqual(20.Seconds(), slept); Assert.AreEqual(10, count); }
public void Stack_trace_is_preserved() { var policy = ActionPolicy .Handle <InvalidOperationException>() .CircuitBreaker(10.Seconds(), 6); SystemUtil.SetSleep(s => { }); StackTest <InvalidOperationException> .Check(policy); }
public void Test_Sleep() { SystemUtil.Sleep(TimeSpan.FromMilliseconds(0)); var flag = false; SystemUtil.SetSleep(s => { Assert.AreEqual(1.Seconds(), s); flag = true; }); SystemUtil.Sleep(1.Seconds()); Assert.IsTrue(flag); }
public void WaitAndRetry() { TimeSpan slept = TimeSpan.Zero; SystemUtil.SetSleep(span => slept += span); var policy = ActionPolicy .Handle <TimeoutException>() .WaitAndRetry(Range.Create(5, i => i.Seconds())); Expect <ArgumentException>(() => policy.Do(RaiseArgument)); Assert.AreEqual(TimeSpan.Zero, slept); Expect <TimeoutException>(() => policy.Do(RaiseTimeout)); Assert.AreEqual(10.Seconds(), slept); }