public void NestedInvoker() { PassThroughInvoker passThrough = new PassThroughInvoker(); this.parameters = new CircuitBreakerStateParameters { stateMachine = this.parameters.stateMachine, settings = this.parameters.settings, invoker = passThrough }; var state = new CircuitBreakerStateNormal(this.parameters); this.stateMachine.SetupProperty(m => m.State, state); int counter = 0; Task t = state.ExecuteAsync <bool>(async() => { await Task.Delay(TimeSpan.FromMilliseconds(1)); counter++; return(true); }); t.Wait(); Assert.AreEqual(1, counter); Assert.IsTrue(passThrough.Verify); }
public void NestedInvoker() { PassThroughInvoker passThrough = new PassThroughInvoker(); Throttle throttle = new Throttle(1, passThrough); int counter = 0; Task t = throttle.ExecuteAsync(async() => { await Task.Delay(TimeSpan.FromMilliseconds(1)); counter++; }); t.Wait(); Assert.AreEqual(1, counter); Assert.IsTrue(passThrough.Verify); }
public void ThrottledNestedInvoker() { PassThroughInvoker passThrough = new PassThroughInvoker(); Throttle throttle = new Throttle(1, passThrough); int counter = 0; Task t1 = throttle.ExecuteAsync(async() => { counter++; await Task.Delay(TimeSpan.FromSeconds(10)); }); Task t2 = throttle.ExecuteAsync(async() => { counter++; await Task.Delay(TimeSpan.FromMilliseconds(1)); }); Assert.AreEqual(1, counter); Assert.IsTrue(t2.IsFaulted); Assert.IsNotNull(t2.Exception); Assert.IsNotNull(t2.Exception.InnerException); Assert.IsTrue(passThrough.Verify); throw t2.Exception.InnerException; }