mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 15:01:56 +00:00
Added RetryFactAttribute
This commit is contained in:
49
tests/Berufsschule_HAM.E2ETests/RetryFactAttribute.cs
Normal file
49
tests/Berufsschule_HAM.E2ETests/RetryFactAttribute.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace Berufsschule_HAM.E2ETests;
|
||||
|
||||
[XunitTestCaseDiscoverer("YourNamespace.RetryFactDiscoverer", "YourAssemblyName")]
|
||||
public class RetryFactAttribute(int maxRetries = 5) : FactAttribute
|
||||
{
|
||||
public int MaxRetries { get; } = maxRetries;
|
||||
}
|
||||
|
||||
public class RetryTestCase : XunitTestCase
|
||||
{
|
||||
private int _maxRetries;
|
||||
|
||||
[Obsolete("Called by the de-serializer", true)]
|
||||
public RetryTestCase() { }
|
||||
|
||||
public RetryTestCase(int maxRetries, ITestMethod testMethod)
|
||||
: base(new NullMessageSink(), TestMethodDisplay.Method, TestMethodDisplayOptions.None, testMethod)
|
||||
{
|
||||
_maxRetries = maxRetries;
|
||||
}
|
||||
|
||||
public override async Task<RunSummary> RunAsync(
|
||||
IMessageSink diagnosticMessageSink,
|
||||
IMessageBus messageBus,
|
||||
object[] constructorArguments,
|
||||
ExceptionAggregator aggregator,
|
||||
CancellationTokenSource cancellationTokenSource)
|
||||
{
|
||||
var summary = new RunSummary();
|
||||
|
||||
for (int i = 1; i <= _maxRetries; i++)
|
||||
{
|
||||
var result = await base.RunAsync(
|
||||
diagnosticMessageSink, messageBus, constructorArguments, aggregator, cancellationTokenSource);
|
||||
|
||||
summary.Aggregate(result);
|
||||
|
||||
if (result.Failed == 0)
|
||||
break; // success, stop retrying
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user