public AsyncJsonServiceWithRetry(int retryLimit, int httpClientTimeoutMilliseconds) : base(httpClientTimeoutMilliseconds) { policy = FastPolly .Handle <Exception>() .WaitAndRetryAsync( retryLimit, retry => TimeSpan.FromMilliseconds(retry * 250)); }
public void ShouldThrowIfExceptionTypesHandledDoNotMatch() { var policy = FastPolly .Handle <ArgumentException>() .WaitAndRetryAsync(3, (retry) => TimeSpan.FromSeconds(retry)); Assert.ThrowsAsync <InvalidOperationException>(async() => { await policy.ExecuteAsync <int>(async() => { throw (await Task.FromResult(new InvalidOperationException())); }); }); }
public async Task ShouldBeAbleToRetryForInheritedExceptions() { var numberOfExecutions = 0; var policy = FastPolly .Handle <Child1Exception>() .WaitAndRetryAsync(3, (retry) => TimeSpan.FromSeconds(retry)); await policy.ExecuteAsync <int>(async() => { numberOfExecutions++; if (numberOfExecutions < 3) { throw new Child2Exception(); } return(await Task.FromResult(0)); }); Assert.That(numberOfExecutions, Is.EqualTo(3)); }