public void Repeat_async_with_log_handler_should_log() { // Arrange Func <Task <int> > customMethodReturnWithCustomExceptionAsync = () => Task.Factory.StartNew <int>(() => throw new CustomException()); int totalAttempts = 0; var callback = new FlowUtils.RetryCallback((a, e) => { totalAttempts = a; }); // Act try { FlowUtils.RetryAsync( customMethodReturnWithCustomExceptionAsync, FlowUtils.CreateCallbackRetryStrategy(callback) + FlowUtils.CreateFixedDelayRetryStrategy(2)).Wait(); } catch (AggregateException) { } // Assert Assert.Equal(2, totalAttempts); }
public void Repeat_with_log_handler_should_log() { // Arrange Action customMethodReturnWithCustomException = () => throw new CustomException(); int totalAttempts = 0; var callback = new FlowUtils.RetryCallback((a, e) => { totalAttempts = a; }); // Act try { FlowUtils.Retry( customMethodReturnWithCustomException, FlowUtils.CreateCallbackRetryStrategy(callback) + FlowUtils.CreateFixedDelayRetryStrategy(2) ); } catch (CustomException) { // suppress our specific exception } // Assert Assert.Equal(2, totalAttempts); }