private async Task <decimal> RunRepeatTestInvoker(ExceptionAggregator aggregator, ITestOutputHelper output, bool collectDump, RepeatAttribute repeatAttribute) { var repeatContext = new RepeatContext { Limit = repeatAttribute.RunCount }; var timeTaken = 0.0M; var testLogger = new LoggedTestInvoker( Test, MessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, BeforeAfterAttributes, aggregator, CancellationTokenSource, output, repeatContext, collectDump); for (repeatContext.CurrentIteration = 0; repeatContext.CurrentIteration < repeatContext.Limit; repeatContext.CurrentIteration++) { timeTaken = await testLogger.RunAsync(); if (aggregator.HasExceptions) { return(timeTaken); } } return(timeTaken); }
private async Task <decimal> InvokeTestMethodAsync(ExceptionAggregator aggregator, ITestOutputHelper output) { var retryAttribute = GetRetryAttribute(TestMethod); var collectDump = TestMethod.GetCustomAttribute <CollectDumpAttribute>() != null; if (!typeof(LoggedTestBase).IsAssignableFrom(TestClass) || retryAttribute == null) { return(await new LoggedTestInvoker(Test, MessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, BeforeAfterAttributes, aggregator, CancellationTokenSource, output, null, collectDump).RunAsync()); } var retryPredicateMethodName = retryAttribute.RetryPredicateName; var retryPredicateMethod = TestClass.GetMethod(retryPredicateMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, new Type[] { typeof(Exception) }, null) ?? throw new InvalidOperationException($"No valid static retry predicate method {retryPredicateMethodName} was found on the type {TestClass.FullName}."); if (retryPredicateMethod.ReturnType != typeof(bool)) { throw new InvalidOperationException($"Retry predicate method {retryPredicateMethodName} on {TestClass.FullName} does not return bool."); } var retryContext = new RetryContext() { Limit = retryAttribute.RetryLimit, Reason = retryAttribute.RetryReason, }; var retryAggregator = new ExceptionAggregator(); var loggedTestInvoker = new LoggedTestInvoker(Test, MessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, BeforeAfterAttributes, retryAggregator, CancellationTokenSource, output, retryContext, collectDump); var totalTime = 0.0M; do { retryAggregator.Clear(); totalTime += await loggedTestInvoker.RunAsync(); retryContext.CurrentIteration++; }while (retryAggregator.HasExceptions && retryContext.CurrentIteration < retryContext.Limit && (retryPredicateMethod.IsStatic ? (bool)retryPredicateMethod.Invoke(null, new object[] { retryAggregator.ToException() }) : (bool)retryPredicateMethod.Invoke(retryContext.TestClassInstance, new object[] { retryAggregator.ToException() })) ); aggregator.Aggregate(retryAggregator); return(totalTime); }