public void RetryOnException_Okay() { int attempts = 0; bool call() { attempts++; return(true); } Retries.RetryOnException <RetryException, bool>(call, "test call").Should().BeTrue(); attempts.Should().Be(1); }
public void RetryOnException_ImmediateAbort() { int attempts = 0; bool call() { attempts++; throw new Exception(); } Action callingRetry = () => Retries.RetryOnException <RetryException, bool>(call, "test call"); callingRetry.Should().Throw <Exception>(); attempts.Should().Be(1); }
public void RetryOnException_RepeatedException() { int attempts = 0; bool call() { attempts++; throw new RetryException(); } Action callingRetry = () => Retries.RetryOnException <RetryException, bool>(call, "test call"); callingRetry.Should().Throw <RetryException>(); attempts.Should().Be(3); }
public void RetryOnException_OneException() { int attempts = 0; bool call() { if (attempts++ == 0) { throw new RetryException(); } return(true); } Retries.RetryOnException <RetryException, bool>(call, "test call").Should().BeTrue(); attempts.Should().Be(2); }
private IEnumerable <Task <bool> > Run <TComponentType>( Func <TComponentType, ComponentTree, Task <bool> > execute, string actionName) where TComponentType : IComponent { foreach (var component in _components.OfType <TComponentType>()) { yield return(Retries.RetryOnException( () => execute(component, this), $"{component.Name}.{actionName}")); } foreach (var child in _children) { foreach (var childRun in child.Run(execute, actionName)) { yield return(childRun); } } }