Skip to content

Update to xunit v3 #2440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -47,7 +47,8 @@
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="xunit.v3" Version="1.0.1" />
<PackageVersion Include="xunit.v3.assert" Version="1.0.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ var configuration = Argument<string>("configuration", "Release");
// EXTERNAL NUGET TOOLS
//////////////////////////////////////////////////////////////////////

#Tool "xunit.runner.console&version=2.9.3"
#Tool "xunit.v3.runner.console&version=1.0.1"
#Tool "dotnet-stryker&version=4.5.0"

//////////////////////////////////////////////////////////////////////
2 changes: 1 addition & 1 deletion eng/Test.targets
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="ReportGenerator" PrivateAssets="all" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
<PackageReference Include="xunit.v3" />
</ItemGroup>

<PropertyGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETFramework'">
2 changes: 1 addition & 1 deletion src/Snippets/Snippets.csproj
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3.assert" />
</ItemGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public void Ctor_Isolated(bool isolated)
[Theory]
public async Task IsolateAsync_NotInitialized_Ok(bool closedAfter)
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var control = new CircuitBreakerManualControl();
await control.IsolateAsync(cancellationToken);
if (closedAfter)
@@ -57,7 +57,7 @@ public async Task ResetAsync_NotInitialized_Ok()
var control = new CircuitBreakerManualControl();

await control
.Invoking(c => c.CloseAsync())
.Invoking(c => c.CloseAsync(TestContext.Current.CancellationToken))
.Should()
.NotThrowAsync();
}
@@ -66,7 +66,7 @@ await control
public async Task Initialize_Twice_Ok()
{
int called = 0;
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var control = new CircuitBreakerManualControl();
control.Initialize(_ => Task.CompletedTask, _ => Task.CompletedTask);
control.Initialize(_ => { called++; return Task.CompletedTask; }, _ => { called++; return Task.CompletedTask; });
@@ -81,7 +81,7 @@ public async Task Initialize_Twice_Ok()
public async Task Initialize_DisposeRegistration_ShuldBeCancelled()
{
int called = 0;
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var control = new CircuitBreakerManualControl();
var reg = control.Initialize(_ => { called++; return Task.CompletedTask; }, _ => { called++; return Task.CompletedTask; });

@@ -99,7 +99,7 @@ public async Task Initialize_DisposeRegistration_ShuldBeCancelled()
[Fact]
public async Task Initialize_Ok()
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var control = new CircuitBreakerManualControl();
var isolateCalled = false;
var resetCalled = false;
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public class CircuitBreakerOptionsTests
public async Task ShouldHandle_EnsureDefaults()
{
var options = new CircuitBreakerStrategyOptions();
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);

(await options.ShouldHandle(new CircuitBreakerPredicateArguments<object>(context, Outcome.FromResult<object>("dummy")))).Should().Be(false);
(await options.ShouldHandle(new CircuitBreakerPredicateArguments<object>(context, Outcome.FromException<object>(new OperationCanceledException())))).Should().Be(false);
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public static class CircuitBreakerPredicateArgumentsTests
public static void Ctor_Ok()
{
var args = new CircuitBreakerPredicateArguments<int>(
ResilienceContextPool.Shared.Get(CancellationToken.None),
ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken),
Outcome.FromResult(1));

args.Context.Should().NotBeNull();
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public void AddCircuitBreaker_Validation()
[Fact]
public void AddCircuitBreaker_IntegrationTest()
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
int opened = 0;
int closed = 0;
int halfOpened = 0;
@@ -127,7 +127,7 @@ public void AddCircuitBreaker_IntegrationTest()
[Fact]
public void AddCircuitBreaker_IntegrationTest_WithBreakDurationGenerator()
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
int opened = 0;
int closed = 0;
int halfOpened = 0;
@@ -191,7 +191,7 @@ public void AddCircuitBreaker_IntegrationTest_WithBreakDurationGenerator()
[Fact]
public async Task AddCircuitBreakers_WithIsolatedManualControl_ShouldBeIsolated()
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var manualControl = new CircuitBreakerManualControl();
await manualControl.IsolateAsync(cancellationToken);

Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public CircuitBreakerResilienceStrategyTests()
null);
}

private static CancellationToken CancellationToken => CancellationToken.None;
private static CancellationToken CancellationToken => TestContext.Current.CancellationToken;

[Fact]
public void Ctor_Ok() =>
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public async Task ResetAsync_NotInitialized_Throws()
var control = new CircuitBreakerManualControl();

await control
.Invoking(c => c.CloseAsync(CancellationToken.None))
.Invoking(c => c.CloseAsync(TestContext.Current.CancellationToken))
.Should()
.NotThrowAsync<InvalidOperationException>();
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public void Ctor_EnsureDefaults()
public async Task IsolateAsync_Ok()
{
// arrange
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
bool called = false;
_options.OnOpened = args =>
{
@@ -69,7 +69,7 @@ public async Task IsolateAsync_Ok()
public async Task BreakAsync_Ok()
{
// arrange
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
bool called = false;
_options.OnClosed = args =>
{
@@ -102,7 +102,7 @@ public async Task BreakAsync_Ok()
[Fact]
public async Task Disposed_EnsureThrows()
{
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);

var controller = CreateController();
controller.Dispose();
@@ -121,7 +121,7 @@ public async Task Disposed_EnsureThrows()
[Fact]
public async Task OnActionPreExecute_CircuitOpenedByValue()
{
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();

await OpenCircuit(controller, Outcome.FromResult(99));
@@ -138,7 +138,7 @@ public async Task OnActionPreExecute_CircuitOpenedByValue()
public async Task OnActionPreExecute_CircuitOpened_EnsureExceptionStackTraceDoesNotGrow(bool innerException)
{
var stacks = new List<string>();
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();

await OpenCircuit(
@@ -175,7 +175,7 @@ await OpenCircuit(
[Fact]
public async Task HalfOpen_EnsureBreakDuration()
{
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();

await TransitionToState(controller, CircuitState.HalfOpen, context);
@@ -187,7 +187,7 @@ public async Task HalfOpen_EnsureBreakDuration()
[Theory]
public async Task HalfOpen_EnsureCorrectStateTransitionAfterExecution(bool success)
{
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();

await TransitionToState(controller, CircuitState.HalfOpen, context);
@@ -213,7 +213,7 @@ public async Task HalfOpen_EnsureCorrectStateTransitionAfterExecution(bool succe
[Fact]
public async Task OnActionPreExecute_CircuitOpenedByException()
{
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();

await OpenCircuit(controller, Outcome.FromException<int>(new InvalidOperationException()));
@@ -227,7 +227,7 @@ public async Task OnActionPreExecute_CircuitOpenedByException()
public async Task OnActionFailure_EnsureLock()
{
// arrange
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var context = ResilienceContextPool.Shared.Get(cancellationToken);

using var executing = new ManualResetEvent(false);
@@ -261,7 +261,7 @@ public async Task OnActionFailure_EnsureLock()
public async Task OnActionPreExecute_HalfOpen()
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
var called = false;
_options.OnHalfOpened = _ =>
{
@@ -293,7 +293,7 @@ public async Task OnActionPreExecute_HalfOpen()
public async Task OnActionSuccess_EnsureCorrectBehavior(CircuitState state, CircuitState expectedState)
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
var called = false;
_options.OnClosed = args =>
{
@@ -329,7 +329,7 @@ public async Task OnActionSuccess_EnsureCorrectBehavior(CircuitState state, Circ
public async Task OnActionFailureAsync_EnsureCorrectBehavior(CircuitState state, CircuitState expectedState, bool shouldBreak)
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
var called = false;
_options.OnOpened = args =>
{
@@ -370,7 +370,7 @@ public async Task OnActionFailureAsync_EnsureCorrectBehavior(CircuitState state,
public async Task OnActionFailureAsync_EnsureBreakDurationGeneration()
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
_options.BreakDurationGenerator = static args =>
{
args.FailureCount.Should().Be(1);
@@ -402,7 +402,7 @@ public async Task OnActionFailureAsync_EnsureBreakDurationGeneration()
public async Task BreakDurationGenerator_EnsureHalfOpenAttempts()
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
var halfOpenAttempts = new List<int>();

_options.BreakDurationGenerator = args =>
@@ -440,7 +440,7 @@ public async Task BreakDurationGenerator_EnsureHalfOpenAttempts()
public async Task OnActionFailureAsync_EnsureBreakDurationNotOverflow(bool overflow)
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();
var shouldBreak = true;
await TransitionToState(controller, CircuitState.HalfOpen, context);
@@ -475,7 +475,7 @@ public async Task OnActionFailureAsync_EnsureBreakDurationNotOverflow(bool overf
public async Task OnActionFailureAsync_VoidResult_EnsureBreakingExceptionNotSet()
{
// arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();
bool shouldBreak = true;
await TransitionToState(controller, CircuitState.Open, context);
@@ -497,7 +497,7 @@ public async Task OnActionFailureAsync_VoidResult_EnsureBreakingExceptionNotSet(
[Fact]
public async Task Flow_Closed_HalfOpen_Closed()
{
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
using var controller = CreateController();

await TransitionToState(controller, CircuitState.HalfOpen, context);
@@ -512,7 +512,7 @@ public async Task Flow_Closed_HalfOpen_Closed()
[Fact]
public async Task Flow_Closed_HalfOpen_Open_HalfOpen_Closed()
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var context = ResilienceContextPool.Shared.Get(cancellationToken);

using var controller = CreateController();
@@ -550,7 +550,7 @@ public async Task Flow_Closed_HalfOpen_Open_HalfOpen_Closed()
[Fact]
public async Task ExecuteScheduledTask_Async_Ok()
{
var cancellationToken = CancellationToken.None;
var cancellationToken = TestContext.Current.CancellationToken;
var context = ResilienceContextPool.Shared.Get(cancellationToken);

var source = new TaskCompletionSource<string>();
@@ -605,7 +605,7 @@ private async Task OpenCircuit(CircuitStateController<int> controller, Outcome<i

await controller.OnHandledOutcomeAsync(
outcome ?? Outcome.FromResult(10),
ResilienceContextPool.Shared.Get().Initialize<int>(true));
ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken).Initialize<int>(true));
}

private void AdvanceTime(TimeSpan timespan) => _timeProvider.Advance(timespan);
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ namespace Polly.Core.Tests.CircuitBreaker.Controller;

public class ScheduledTaskExecutorTests
{
private static CancellationToken CancellationToken => CancellationToken.None;
private static CancellationToken CancellationToken => TestContext.Current.CancellationToken;

[Fact]
public async Task ScheduleTask_Success_EnsureExecuted()
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public static class OnCircuitClosedArgumentsTests
public static void Ctor_Ok()
{
// Arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);

// Act
var args = new OnCircuitClosedArguments<int>(context, Outcome.FromResult(1), true);
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public static class OnCircuitHalfOpenedArgumentsTests
public static void Ctor_Ok()
{
// Arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);

// Act
var target = new OnCircuitHalfOpenedArguments(context);
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ public static class OnCircuitOpenedArgumentsTests
public static void Ctor_Ok()
{
// Arrange
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);

// Act
var args = new OnCircuitOpenedArguments<int>(context, Outcome.FromResult(1), TimeSpan.FromSeconds(2), true);
2 changes: 1 addition & 1 deletion test/Polly.Core.Tests/Fallback/FallbackHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ public class FallbackHandlerTests
public async Task GenerateAction_Generic_Ok()
{
var handler = FallbackHelper.CreateHandler(_ => true, () => Outcome.FromResult("secondary"));
var context = ResilienceContextPool.Shared.Get();
var context = ResilienceContextPool.Shared.Get(TestContext.Current.CancellationToken);
var outcome = await handler.GetFallbackOutcomeAsync(new FallbackActionArguments<string>(context, Outcome.FromResult("primary")))!;

outcome.Result.Should().Be("secondary");
Loading