private async Task <Tuple <decimal, string> > RunTestCaseWithRetryAsync(RetryAttribute retryAttribute, ExceptionAggregator aggregator) { var totalTimeTaken = 0m; List <string> messages = new(); var numAttempts = Math.Max(1, retryAttribute.MaxRetries); for (var attempt = 1; attempt <= numAttempts; attempt++) { var result = await base.InvokeTestAsync(aggregator); totalTimeTaken += result.Item1; messages.Add(result.Item2); if (!aggregator.HasExceptions) { break; } else if (attempt < numAttempts) { // We can't use the ITestOutputHelper here because there's no active test messages.Add($"[{TestCase.DisplayName}] Attempt {attempt} of {retryAttribute.MaxRetries} failed due to {aggregator.ToException()}"); await Task.Delay(5000); aggregator.Clear(); } } return(new(totalTimeTaken, string.Join(Environment.NewLine, messages))); }
protected async Task <decimal> RetryAsync(RetryAttribute retryAttribute, object testClassInstance) { var attempts = 0; var timeTaken = 0.0M; for (attempts = 0; attempts < retryAttribute.MaxRetries; attempts++) { timeTaken = await base.InvokeTestMethodAsync(testClassInstance); if (!Aggregator.HasExceptions) { return(timeTaken); } else if (attempts < retryAttribute.MaxRetries - 1) { _testOutputHelper.WriteLine($"Retrying test, attempt {attempts} of {retryAttribute.MaxRetries} failed."); await Task.Delay(5000); Aggregator.Clear(); } } return(timeTaken); }