-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed schedulers for replay subjects
- Loading branch information
1 parent
0dae323
commit 3ddfa0f
Showing
20 changed files
with
401 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// See https://github.com/JoshKeegan/xRetry | ||
|
||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace TestingUtils | ||
{ | ||
/// <summary> | ||
/// Attribute that is applied to a method to indicate that it is a fact that should be run | ||
/// by the test runner up to MaxRetries times, until it succeeds. | ||
/// </summary> | ||
[XunitTestCaseDiscoverer("TestingUtils.RetryFactDiscoverer", "TestingUtils")] | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class RetryFactAttribute : FactAttribute | ||
{ | ||
public readonly int MaxRetries; | ||
public readonly int DelayBetweenRetriesMs; | ||
public readonly SkipOnPlatform[] PlatformsToSkip; | ||
private string? _skip; | ||
|
||
/// <summary> | ||
/// Ctor | ||
/// </summary> | ||
/// <param name="maxRetries">The number of times to run a test for until it succeeds</param> | ||
/// <param name="delayBetweenRetriesMs">The amount of time (in ms) to wait between each test run attempt</param> | ||
/// <param name="skipOn">platforms to skip testing on</param> | ||
public RetryFactAttribute(int maxRetries = 5, int delayBetweenRetriesMs = 0, params SkipOnPlatform[] skipOn) | ||
{ | ||
if (maxRetries < 1) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(maxRetries) + " must be >= 1"); | ||
} | ||
if (delayBetweenRetriesMs < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(delayBetweenRetriesMs) + " must be >= 0"); | ||
} | ||
|
||
MaxRetries = !UnitTestDetector.IsCI() ? 1 : maxRetries; | ||
DelayBetweenRetriesMs = delayBetweenRetriesMs; | ||
PlatformsToSkip = skipOn; | ||
} | ||
|
||
public override string? Skip | ||
{ | ||
get => UnitTestDetector.IsCI() && PlatformsToSkip.Any(UnitTestDetector.PlatformToSkipPredicate) | ||
? "Skipped on platform" + ( string.IsNullOrWhiteSpace(_skip) ? "" : " because " + _skip ) | ||
: null; | ||
set => _skip = value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace TestingUtils | ||
{ | ||
public class RetryFactDiscoverer : IXunitTestCaseDiscoverer | ||
{ | ||
private readonly IMessageSink _messageSink; | ||
|
||
public RetryFactDiscoverer(IMessageSink messageSink) | ||
{ | ||
_messageSink = messageSink; | ||
} | ||
|
||
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, | ||
IAttributeInfo factAttribute) | ||
{ | ||
IXunitTestCase testCase; | ||
|
||
if (testMethod.Method.GetParameters().Any()) | ||
{ | ||
testCase = new ExecutionErrorTestCase(_messageSink, discoveryOptions.MethodDisplayOrDefault(), | ||
discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, | ||
"[RetryFact] methods are not allowed to have parameters. Did you mean to use [RetryTheory]?"); | ||
} | ||
else if (testMethod.Method.IsGenericMethodDefinition) | ||
{ | ||
testCase = new ExecutionErrorTestCase(_messageSink, discoveryOptions.MethodDisplayOrDefault(), | ||
discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, | ||
"[RetryFact] methods are not allowed to be generic."); | ||
} | ||
else | ||
{ | ||
var maxRetries = factAttribute.GetNamedArgument<int>(nameof(RetryFactAttribute.MaxRetries)); | ||
var delayBetweenRetriesMs = | ||
factAttribute.GetNamedArgument<int>(nameof(RetryFactAttribute.DelayBetweenRetriesMs)); | ||
testCase = new RetryTestCase(_messageSink, discoveryOptions.MethodDisplayOrDefault(), | ||
discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, maxRetries, delayBetweenRetriesMs); | ||
} | ||
|
||
return new[] { testCase }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace TestingUtils | ||
{ | ||
[Serializable] | ||
public class RetryTestCase : XunitTestCase, IRetryableTestCase | ||
{ | ||
public int MaxRetries { get; private set; } | ||
public int DelayBetweenRetriesMs { get; private set; } | ||
|
||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[Obsolete( | ||
"Called by the de-serializer; should only be called by deriving classes for de-serialization purposes", true)] | ||
public RetryTestCase() { } | ||
|
||
public RetryTestCase( | ||
IMessageSink diagnosticMessageSink, | ||
TestMethodDisplay defaultMethodDisplay, | ||
TestMethodDisplayOptions defaultMethodDisplayOptions, | ||
ITestMethod testMethod, | ||
int maxRetries, | ||
int delayBetweenRetriesMs, | ||
object[]? testMethodArguments = null) | ||
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, | ||
testMethodArguments) | ||
{ | ||
MaxRetries = maxRetries; | ||
DelayBetweenRetriesMs = delayBetweenRetriesMs; | ||
} | ||
|
||
public override Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, | ||
object[] constructorArguments, ExceptionAggregator aggregator, | ||
CancellationTokenSource cancellationTokenSource) => | ||
RetryTestCaseRunner.RunAsync(this, diagnosticMessageSink, messageBus, cancellationTokenSource, | ||
blockingMessageBus => new XunitTestCaseRunner(this, DisplayName, SkipReason, constructorArguments, | ||
TestMethodArguments, blockingMessageBus, aggregator, cancellationTokenSource) | ||
.RunAsync()); | ||
|
||
public override void Serialize(IXunitSerializationInfo data) | ||
{ | ||
base.Serialize(data); | ||
|
||
data.AddValue("MaxRetries", MaxRetries); | ||
data.AddValue("DelayBetweenRetriesMs", DelayBetweenRetriesMs); | ||
} | ||
|
||
public override void Deserialize(IXunitSerializationInfo data) | ||
{ | ||
base.Deserialize(data); | ||
|
||
MaxRetries = data.GetValue<int>("MaxRetries"); | ||
DelayBetweenRetriesMs = data.GetValue<int>("DelayBetweenRetriesMs"); | ||
} | ||
} | ||
} |
Oops, something went wrong.