diff --git a/.github/workflows/sdk_build.yml b/.github/workflows/sdk_build.yml index 540efc41b..072288e26 100644 --- a/.github/workflows/sdk_build.yml +++ b/.github/workflows/sdk_build.yml @@ -233,6 +233,7 @@ jobs: --logger "trx;LogFilePrefix=${{ matrix.prefix }}" \ --logger "GitHubActions;report-warnings=false" \ --results-directory "${{ github.workspace }}/TestResults" \ + /p:RuntimeIdentifier=linux-x64 \ /p:CollectCoverage=true \ /p:CoverletOutputFormat=opencover \ /p:GITHUB_ACTIONS=false @@ -298,6 +299,7 @@ jobs: --logger "trx;LogFilePrefix=${{ matrix.prefix }}" \ --logger "GitHubActions;report-warnings=false" \ --results-directory "${{ github.workspace }}/TestResults" \ + /p:RuntimeIdentifier=linux-x64 \ /p:CollectCoverage=true \ /p:CoverletOutputFormat=opencover \ /p:GITHUB_ACTIONS=false diff --git a/Directory.Packages.props b/Directory.Packages.props index c92c13c18..394243a4d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -43,6 +43,7 @@ + @@ -53,8 +54,8 @@ - - + + \ No newline at end of file diff --git a/examples/Workflow/WorkflowUnitTest/WorkflowUnitTest.csproj b/examples/Workflow/WorkflowUnitTest/WorkflowUnitTest.csproj index d0f391a25..abadcf530 100644 --- a/examples/Workflow/WorkflowUnitTest/WorkflowUnitTest.csproj +++ b/examples/Workflow/WorkflowUnitTest/WorkflowUnitTest.csproj @@ -8,7 +8,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Dapr.Testcontainers.Xunit/Dapr.Testcontainers.Xunit.csproj b/src/Dapr.Testcontainers.Xunit/Dapr.Testcontainers.Xunit.csproj index 5cd2fd2b8..5ba7a9d4a 100644 --- a/src/Dapr.Testcontainers.Xunit/Dapr.Testcontainers.Xunit.csproj +++ b/src/Dapr.Testcontainers.Xunit/Dapr.Testcontainers.Xunit.csproj @@ -8,7 +8,7 @@ - + diff --git a/test/Dapr.AI.Test/Dapr.AI.Test.csproj b/test/Dapr.AI.Test/Dapr.AI.Test.csproj index b4a07c1fb..1cc786695 100644 --- a/test/Dapr.AI.Test/Dapr.AI.Test.csproj +++ b/test/Dapr.AI.Test/Dapr.AI.Test.csproj @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Actors.Analyzers.Test/Dapr.Actors.Analyzers.Test.csproj b/test/Dapr.Actors.Analyzers.Test/Dapr.Actors.Analyzers.Test.csproj index a73518742..724ff1366 100644 --- a/test/Dapr.Actors.Analyzers.Test/Dapr.Actors.Analyzers.Test.csproj +++ b/test/Dapr.Actors.Analyzers.Test/Dapr.Actors.Analyzers.Test.csproj @@ -13,9 +13,9 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Dapr.Actors.Analyzers.Test/TimerCallbackMethodPresentAnalyzerTests.cs b/test/Dapr.Actors.Analyzers.Test/TimerCallbackMethodPresentAnalyzerTests.cs index e2d554bd2..0def07285 100644 --- a/test/Dapr.Actors.Analyzers.Test/TimerCallbackMethodPresentAnalyzerTests.cs +++ b/test/Dapr.Actors.Analyzers.Test/TimerCallbackMethodPresentAnalyzerTests.cs @@ -49,7 +49,7 @@ public async Task DoSomethingAsync() """; context.ExpectedDiagnostics.Clear(); - await context.RunAsync(); + await context.RunAsync(TestContext.Current.CancellationToken); } [Fact] @@ -80,7 +80,7 @@ private static async Task TimerCallback(byte[] data) """; context.ExpectedDiagnostics.Clear(); - await context.RunAsync(); + await context.RunAsync(TestContext.Current.CancellationToken); } [Fact] @@ -111,7 +111,7 @@ private static async Task TimerCallback(byte[] data) """; context.ExpectedDiagnostics.Clear(); - await context.RunAsync(); + await context.RunAsync(TestContext.Current.CancellationToken); } [Fact] @@ -138,7 +138,7 @@ public async Task DoSomethingAsync() context.ExpectedDiagnostics.Add(new DiagnosticResult(TimerCallbackMethodPresentAnalyzer.DaprTimerCallbackMethodRule) .WithSpan(8, 45, 8, 60) .WithArguments("TimerCallback", "TestActorTimerRegistrationTimerCallbackNotPresent")); - await context.RunAsync(); + await context.RunAsync(TestContext.Current.CancellationToken); } } diff --git a/test/Dapr.Actors.AspNetCore.IntegrationTest/ActivationTests.cs b/test/Dapr.Actors.AspNetCore.IntegrationTest/ActivationTests.cs index 83e66e9d8..2f60c6c52 100644 --- a/test/Dapr.Actors.AspNetCore.IntegrationTest/ActivationTests.cs +++ b/test/Dapr.Actors.AspNetCore.IntegrationTest/ActivationTests.cs @@ -32,7 +32,7 @@ public class ActivationTests [Fact] public async Task CanActivateActorWithDependencyInjection() { - using var factory = new AppWebApplicationFactory(); + await using var factory = new AppWebApplicationFactory(); var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); // Doing this twice verifies that the Actor stays active and retains state using DI. @@ -47,8 +47,8 @@ public async Task CanActivateActorWithDependencyInjection() private async Task IncrementCounterAsync(HttpClient httpClient, string actorId) { - var actorTypeName = nameof(DependencyInjectionActor); - var methodName = nameof(DependencyInjectionActor.IncrementAsync); + const string actorTypeName = nameof(DependencyInjectionActor); + const string methodName = nameof(DependencyInjectionActor.IncrementAsync); var request = new HttpRequestMessage(HttpMethod.Put, $"http://localhost/actors/{actorTypeName}/{actorId}/method/{methodName}"); var response = await httpClient.SendAsync(request); @@ -59,7 +59,7 @@ private async Task IncrementCounterAsync(HttpClient httpClient, string a private async Task DeactivateActor(HttpClient httpClient, string actorId) { - var actorTypeName = nameof(DependencyInjectionActor); + const string actorTypeName = nameof(DependencyInjectionActor); var request = new HttpRequestMessage(HttpMethod.Delete, $"http://localhost/actors/{actorTypeName}/{actorId}"); var response = await httpClient.SendAsync(request); @@ -82,4 +82,4 @@ private async Task Assert2XXStatusAsync(HttpResponseMessage response) var text = await response.Content.ReadAsStringAsync(); throw new XunitException($"The response failed with a {response.StatusCode} and body:" + Environment.NewLine + text); } -} \ No newline at end of file +} diff --git a/test/Dapr.Actors.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs b/test/Dapr.Actors.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs index 3362eb107..23a744194 100644 --- a/test/Dapr.Actors.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs +++ b/test/Dapr.Actors.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs @@ -13,7 +13,7 @@ namespace Dapr.Actors.AspNetCore.IntegrationTest; -using Dapr.Actors.AspNetCore.IntegrationTest.App; +using App; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -36,4 +36,4 @@ protected override IHostBuilder CreateHostBuilder() }); return builder; } -} \ No newline at end of file +} diff --git a/test/Dapr.Actors.AspNetCore.IntegrationTest/Dapr.Actors.AspNetCore.IntegrationTest.csproj b/test/Dapr.Actors.AspNetCore.IntegrationTest/Dapr.Actors.AspNetCore.IntegrationTest.csproj index 394cc9def..b1d6ff808 100644 --- a/test/Dapr.Actors.AspNetCore.IntegrationTest/Dapr.Actors.AspNetCore.IntegrationTest.csproj +++ b/test/Dapr.Actors.AspNetCore.IntegrationTest/Dapr.Actors.AspNetCore.IntegrationTest.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Actors.AspNetCore.IntegrationTest/HostingTests.cs b/test/Dapr.Actors.AspNetCore.IntegrationTest/HostingTests.cs index 0460b47c2..0d6857d88 100644 --- a/test/Dapr.Actors.AspNetCore.IntegrationTest/HostingTests.cs +++ b/test/Dapr.Actors.AspNetCore.IntegrationTest/HostingTests.cs @@ -54,10 +54,10 @@ public void MapActorsHandlers_WithoutAddActors_Throws() [Fact] public async Task MapActorsHandlers_IncludesHealthChecks() { - using var factory = new AppWebApplicationFactory(); + await using var factory = new AppWebApplicationFactory(); var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var response = await httpClient.GetAsync("/healthz"); + var response = await httpClient.GetAsync("/healthz", TestContext.Current.CancellationToken); await Assert2XXStatusAsync(response); } @@ -68,7 +68,7 @@ public async Task ActorsHealthz_ShouldNotRequireAuthorization() var server = host.GetTestServer(); var httpClient = server.CreateClient(); - var response = await httpClient.GetAsync("/healthz"); + var response = await httpClient.GetAsync("/healthz", TestContext.Current.CancellationToken); await Assert2XXStatusAsync(response); } @@ -82,10 +82,10 @@ public async Task MapActorsHandlers_ActorHealthCheckDoesNotConflict() var server = host.GetTestServer(); var httpClient = server.CreateClient(); - var response = await httpClient.GetAsync("/healthz"); + var response = await httpClient.GetAsync("/healthz", TestContext.Current.CancellationToken); await Assert2XXStatusAsync(response); - var text = await response.Content.ReadAsStringAsync(); + var text = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); Assert.Equal("Ice Cold, Solid Gold!", text); } @@ -97,7 +97,7 @@ public async Task MapActorsHandlers_WorksWithFallbackRoute() var server = host.GetTestServer(); var httpClient = server.CreateClient(); - var response = await httpClient.GetAsync("/dapr/config"); + var response = await httpClient.GetAsync("/dapr/config", TestContext.Current.CancellationToken); await Assert2XXStatusAsync(response); } @@ -237,4 +237,4 @@ private async Task Assert2XXStatusAsync(HttpResponseMessage response) var text = await response.Content.ReadAsStringAsync(); throw new XunitException($"The response failed with a {response.StatusCode} and body:" + Environment.NewLine + text); } -} \ No newline at end of file +} diff --git a/test/Dapr.Actors.AspNetCore.Test/Dapr.Actors.AspNetCore.Test.csproj b/test/Dapr.Actors.AspNetCore.Test/Dapr.Actors.AspNetCore.Test.csproj index 9f9e43119..d7fc76761 100644 --- a/test/Dapr.Actors.AspNetCore.Test/Dapr.Actors.AspNetCore.Test.csproj +++ b/test/Dapr.Actors.AspNetCore.Test/Dapr.Actors.AspNetCore.Test.csproj @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Actors.AspNetCore.Test/Runtime/ActorsEndpointRouteBuilderExtensionsTests.cs b/test/Dapr.Actors.AspNetCore.Test/Runtime/ActorsEndpointRouteBuilderExtensionsTests.cs index 9fc67760e..0bd685d48 100644 --- a/test/Dapr.Actors.AspNetCore.Test/Runtime/ActorsEndpointRouteBuilderExtensionsTests.cs +++ b/test/Dapr.Actors.AspNetCore.Test/Runtime/ActorsEndpointRouteBuilderExtensionsTests.cs @@ -35,9 +35,9 @@ public async Task MapActorsHandlers_MapDaprConfigEndpoint() var server = host.GetTestServer(); var httpClient = server.CreateClient(); - var response = await httpClient.GetAsync("/dapr/config"); + var response = await httpClient.GetAsync("/dapr/config", TestContext.Current.CancellationToken); - var text = await response.Content.ReadAsStringAsync(); + var text = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); Assert.Equal(@"{""entities"":[""TestActor""],""reentrancy"":{""enabled"":false}}", text); } @@ -98,4 +98,4 @@ private class TestActor : Actor, ITestActor { public TestActor(ActorHost host) : base(host) { } } -} \ No newline at end of file +} diff --git a/test/Dapr.Actors.Generators.Test/ActorClientGeneratorTests.cs b/test/Dapr.Actors.Generators.Test/ActorClientGeneratorTests.cs index 3515bc8b0..2307f72fd 100644 --- a/test/Dapr.Actors.Generators.Test/ActorClientGeneratorTests.cs +++ b/test/Dapr.Actors.Generators.Test/ActorClientGeneratorTests.cs @@ -85,7 +85,7 @@ private static VerifyCS.Test CreateTest(string originalSource, string? generated [Fact] public async Task TestMethodWithNoArgumentsOrReturnValue() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -98,7 +98,7 @@ public interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -122,13 +122,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestInternalInterface() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -141,7 +141,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -165,13 +165,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestSingleGenericInternalInterface() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -184,7 +184,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -208,13 +208,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMultipleGenericsInternalInterface() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -227,7 +227,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -251,13 +251,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestRenamedClient() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -270,7 +270,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -294,13 +294,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.MyTestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.MyTestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestSingleGenericRenamedClient() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -313,7 +313,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -337,13 +337,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.MyTestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.MyTestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMultipleGenericsRenamedClient() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -356,7 +356,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -380,13 +380,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.MyTestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.MyTestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestCustomNamespace() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -399,7 +399,7 @@ internal interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace MyTest { @@ -423,13 +423,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "MyTest.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "MyTest.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestRenamedMethod() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -444,7 +444,7 @@ public interface ITestActor } "; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -468,13 +468,13 @@ public System.Threading.Tasks.Task TestMethod() } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithArgumentsButNoReturnValue() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -490,7 +490,7 @@ public interface ITestActor } "; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -514,13 +514,13 @@ public System.Threading.Tasks.Task TestMethod(Test.TestValue value) } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithNoArgumentsButReturnValue() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -535,7 +535,7 @@ public interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -559,13 +559,13 @@ public TestActorClient(Dapr.Actors.Client.ActorProxy actorProxy) } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithArgumentsAndReturnValue() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading.Tasks; @@ -582,7 +582,7 @@ public interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -606,7 +606,7 @@ public TestActorClient(Dapr.Actors.Client.ActorProxy actorProxy) } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] @@ -650,13 +650,13 @@ public System.Threading.Tasks.Task TestMethodAsync(System.Threading.Cancellation } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithDefaultCancellationTokenArgument() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading; using System.Threading.Tasks; @@ -670,7 +670,7 @@ public interface ITestActor } }"; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -694,13 +694,13 @@ public System.Threading.Tasks.Task TestMethodAsync(System.Threading.Cancellation } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithValueAndCancellationTokenArguments() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading; using System.Threading.Tasks; @@ -717,7 +717,7 @@ public interface ITestActor } "; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -741,7 +741,7 @@ public System.Threading.Tasks.Task TestMethodAsync(Test.TestValue value, System. } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] @@ -764,7 +764,7 @@ public interface ITestActor } "; - var generatedSource = @"// + const string generatedSource = @"// #nullable enable namespace Test { @@ -788,13 +788,13 @@ public System.Threading.Tasks.Task TestMethodAsync(Test.TestValue value, System. } }"; - await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(); + await CreateTest(originalSource, "Test.TestActorClient.g.cs", generatedSource).RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithReversedArguments() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading; using System.Threading.Tasks; @@ -817,13 +817,13 @@ public interface ITestActor .WithSpan(13, 48, 13, 65) .WithMessage("Cancellation tokens must be the last argument")); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithTooManyArguments() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading; using System.Threading.Tasks; @@ -846,13 +846,13 @@ public interface ITestActor .WithSpan(13, 14, 13, 29) .WithMessage("Only methods with a single argument or a single argument followed by a cancellation token are supported")); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Fact] public async Task TestMethodWithFarTooManyArguments() { - var originalSource = @" + const string originalSource = @" using Dapr.Actors.Generators; using System.Threading; using System.Threading.Tasks; @@ -875,6 +875,6 @@ public interface ITestActor .WithSpan(13, 14, 13, 29) .WithMessage("Only methods with a single argument or a single argument followed by a cancellation token are supported")); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } } diff --git a/test/Dapr.Actors.Generators.Test/Dapr.Actors.Generators.Test.csproj b/test/Dapr.Actors.Generators.Test/Dapr.Actors.Generators.Test.csproj index 9e9a9e4db..1ad452e2f 100644 --- a/test/Dapr.Actors.Generators.Test/Dapr.Actors.Generators.Test.csproj +++ b/test/Dapr.Actors.Generators.Test/Dapr.Actors.Generators.Test.csproj @@ -16,7 +16,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Dapr.Actors.Generators.Test/Helpers/SyntaxFactoryHelpersTests.cs b/test/Dapr.Actors.Generators.Test/Helpers/SyntaxFactoryHelpersTests.cs index 6d36cc122..f13b8e759 100644 --- a/test/Dapr.Actors.Generators.Test/Helpers/SyntaxFactoryHelpersTests.cs +++ b/test/Dapr.Actors.Generators.Test/Helpers/SyntaxFactoryHelpersTests.cs @@ -10,18 +10,16 @@ public class SyntaxFactoryHelpersTests public void ThrowArgumentNullException_GenerateThrowArgumentNullExceptionSyntaxWithGivenArgumentName() { // Arrange - var argumentName = "arg0"; - var expectedSource = $@"throw new System.ArgumentNullException(nameof(arg0));"; - var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource) - .GetRoot() + const string argumentName = "arg0"; + const string expectedSource = $@"throw new System.ArgumentNullException(nameof(arg0));"; + var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource, cancellationToken: TestContext.Current.CancellationToken).GetRoot(TestContext.Current.CancellationToken) .NormalizeWhitespace() .ToFullString(); // Act var generatedSource = SyntaxFactory.ExpressionStatement(SyntaxFactoryHelpers.ThrowArgumentNullException(argumentName)) .SyntaxTree - .GetRoot() - .NormalizeWhitespace() + .GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); // Assert @@ -32,21 +30,18 @@ public void ThrowArgumentNullException_GenerateThrowArgumentNullExceptionSyntaxW public void ThrowIfArgumentNullException_GivesNullCheckSyntaxWithGivenArgumentName() { // Arrange - var argumentName = "arg0"; - var expectedSource = $@"if (arg0 is null) -{{ + const string argumentName = "arg0"; + const string expectedSource = @"if (arg0 is null) +{ throw new System.ArgumentNullException(nameof(arg0)); -}}"; - var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource) - .GetRoot() - .NormalizeWhitespace() +}"; + var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource, cancellationToken: TestContext.Current.CancellationToken).GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); // Act var generatedSource = SyntaxFactoryHelpers.ThrowIfArgumentNull(argumentName) .SyntaxTree - .GetRoot() - .NormalizeWhitespace() + .GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); // Assert @@ -57,7 +52,7 @@ public void ThrowIfArgumentNullException_GivesNullCheckSyntaxWithGivenArgumentNa public void ActorProxyInvokeMethodAsync_WithoutReturnTypeAndParamters_ReturnNonGenericInvokeMethodAsync() { // Arrange - var remoteMethodName = "RemoteMethodToCall"; + const string remoteMethodName = "RemoteMethodToCall"; var remoteMethodParameters = Array.Empty(); var remoteMethodReturnTypes = Array.Empty(); var actorProxMemberAccessSyntax = SyntaxFactory.MemberAccessExpression( @@ -65,10 +60,8 @@ public void ActorProxyInvokeMethodAsync_WithoutReturnTypeAndParamters_ReturnNonG SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName("actorProxy") ); - var expectedSource = $@"this.actorProxy.InvokeMethodAsync(""RemoteMethodToCall"")"; - var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource) - .GetRoot() - .NormalizeWhitespace() + const string expectedSource = @"this.actorProxy.InvokeMethodAsync(""RemoteMethodToCall"")"; + var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource, cancellationToken: TestContext.Current.CancellationToken).GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); // Act @@ -78,8 +71,7 @@ public void ActorProxyInvokeMethodAsync_WithoutReturnTypeAndParamters_ReturnNonG remoteMethodParameters, remoteMethodReturnTypes) .SyntaxTree - .GetRoot() - .NormalizeWhitespace() + .GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); ; // Assert @@ -90,18 +82,15 @@ public void ActorProxyInvokeMethodAsync_WithoutReturnTypeAndParamters_ReturnNonG public void NameOfExpression() { // Arrange - var argumentName = "arg0"; - var expectedSource = $@"nameof(arg0)"; - var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource) - .GetRoot() - .NormalizeWhitespace() + const string argumentName = "arg0"; + const string expectedSource = $@"nameof(arg0)"; + var expectedSourceNormalized = SyntaxFactory.ParseSyntaxTree(expectedSource, cancellationToken: TestContext.Current.CancellationToken).GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); // Act var generatedSource = SyntaxFactoryHelpers.NameOfExpression(argumentName) .SyntaxTree - .GetRoot() - .NormalizeWhitespace() + .GetRoot(TestContext.Current.CancellationToken).NormalizeWhitespace() .ToFullString(); // Assert @@ -129,4 +118,4 @@ public void GetSyntaxKinds_GenerateSyntaxForGivenAccessibility(Accessibility acc Assert.Equal(expectedSyntaxKinds.Count, generatedSyntaxKinds.Count); } -} \ No newline at end of file +} diff --git a/test/Dapr.Actors.Test/ActorCodeBuilderTests.cs b/test/Dapr.Actors.Test/ActorCodeBuilderTests.cs index b82c56fc5..f0d777d7a 100644 --- a/test/Dapr.Actors.Test/ActorCodeBuilderTests.cs +++ b/test/Dapr.Actors.Test/ActorCodeBuilderTests.cs @@ -46,7 +46,7 @@ public async Task ActorCodeBuilder_BuildDispatcher() var request = new ActorRequestMessageBody(0); var response = new WrappedRequestMessageFactory(); - var body = (WrappedMessage)await dispatcher.DispatchAsync(impl, methodId, request, response, default); + var body = (WrappedMessage)await dispatcher.DispatchAsync(impl, methodId, request, response, TestContext.Current.CancellationToken); dynamic bodyValue = body.Value; Assert.Equal(5, (int)bodyValue.retVal); } diff --git a/test/Dapr.Actors.Test/ActorStateManagerTest.cs b/test/Dapr.Actors.Test/ActorStateManagerTest.cs index ae15e89cd..b5ae157a2 100644 --- a/test/Dapr.Actors.Test/ActorStateManagerTest.cs +++ b/test/Dapr.Actors.Test/ActorStateManagerTest.cs @@ -73,7 +73,7 @@ public async Task StateWithTTL() Assert.Equal("value1", await mngr.GetStateAsync("key1", token)); Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); - await Task.Delay(TimeSpan.FromSeconds(1.5)); + await Task.Delay(TimeSpan.FromSeconds(1.5), TestContext.Current.CancellationToken); await Assert.ThrowsAsync(() => mngr.GetStateAsync("key1", token)); await Assert.ThrowsAsync(() => mngr.GetStateAsync("key2", token)); @@ -83,7 +83,7 @@ public async Task StateWithTTL() await mngr.AddStateAsync("key2", "value2", token); Assert.Equal("value1", await mngr.GetStateAsync("key1", token)); Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); - await Task.Delay(TimeSpan.FromSeconds(1.5)); + await Task.Delay(TimeSpan.FromSeconds(1.5), TestContext.Current.CancellationToken); Assert.Equal("value1", await mngr.GetStateAsync("key1", token)); Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); } @@ -112,7 +112,7 @@ public async Task StateRemoveAddTTL() Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); // TTL is removed so state should not expire. - await Task.Delay(TimeSpan.FromSeconds(1.5)); + await Task.Delay(TimeSpan.FromSeconds(1.5), TestContext.Current.CancellationToken); Assert.Equal("value1", await mngr.GetStateAsync("key1", token)); Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); @@ -121,7 +121,7 @@ public async Task StateRemoveAddTTL() await mngr.SetStateAsync("key2", "value2", TimeSpan.FromSeconds(1), token); Assert.Equal("value1", await mngr.GetStateAsync("key1", token)); Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); - await Task.Delay(TimeSpan.FromSeconds(1.5)); + await Task.Delay(TimeSpan.FromSeconds(1.5), TestContext.Current.CancellationToken); await Assert.ThrowsAsync(() => mngr.GetStateAsync("key1", token)); await Assert.ThrowsAsync(() => mngr.GetStateAsync("key2", token)); } @@ -149,7 +149,7 @@ public async Task StateDaprdExpireTime() .Returns(Task.FromResult(new ActorStateResponse("", null))); // Key should be expired after 1 seconds. - await Task.Delay(TimeSpan.FromSeconds(1.5)); + await Task.Delay(TimeSpan.FromSeconds(1.5), TestContext.Current.CancellationToken); await Assert.ThrowsAsync(() => mngr.GetStateAsync("key1", token)); await Assert.ThrowsAsync(() => mngr.RemoveStateAsync("key1", token)); await mngr.AddStateAsync("key1", "value2", TimeSpan.FromSeconds(1), token); @@ -188,4 +188,4 @@ public async Task RemoveState() Assert.Equal("value1", await mngr.GetStateAsync("key1", token)); Assert.Equal("value2", await mngr.GetStateAsync("key2", token)); } -} \ No newline at end of file +} diff --git a/test/Dapr.Actors.Test/Dapr.Actors.Test.csproj b/test/Dapr.Actors.Test/Dapr.Actors.Test.csproj index f28cbaef5..c4f15a1c6 100644 --- a/test/Dapr.Actors.Test/Dapr.Actors.Test.csproj +++ b/test/Dapr.Actors.Test/Dapr.Actors.Test.csproj @@ -13,7 +13,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs b/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs index c39e940ee..8db7ac25e 100644 --- a/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs +++ b/test/Dapr.Actors.Test/Runtime/ActorRuntimeTests.cs @@ -102,7 +102,7 @@ public async Task NoActivateMessageFromRuntime() Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); var output = new MemoryStream(); - await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output); + await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output, TestContext.Current.CancellationToken); var text = Encoding.UTF8.GetString(output.ToArray()); Assert.Equal("\"hi\"", text); @@ -229,7 +229,7 @@ public async Task Actor_UsesCustomActivator() Assert.Contains(actorType.Name, runtime.RegisteredActors.Select(a => a.Type.ActorTypeName), StringComparer.InvariantCulture); var output = new MemoryStream(); - await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output); + await runtime.DispatchWithoutRemotingAsync(actorType.Name, "abc", nameof(MyActor.MyMethod), new MemoryStream(), output, TestContext.Current.CancellationToken); var text = Encoding.UTF8.GetString(output.ToArray()); Assert.Equal("\"hi\"", text); @@ -474,4 +474,4 @@ public override Task DeleteAsync(ActorActivatorState state) return base.DeleteAsync(state); } } -} \ No newline at end of file +} diff --git a/test/Dapr.Analyzers.Common/Dapr.Analyzers.Common.csproj b/test/Dapr.Analyzers.Common/Dapr.Analyzers.Common.csproj index 8a225e612..bf10d03f4 100644 --- a/test/Dapr.Analyzers.Common/Dapr.Analyzers.Common.csproj +++ b/test/Dapr.Analyzers.Common/Dapr.Analyzers.Common.csproj @@ -12,7 +12,7 @@ - + diff --git a/test/Dapr.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs b/test/Dapr.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs index 24df9b66d..96b5ef1b4 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/AppWebApplicationFactory.cs @@ -13,8 +13,8 @@ namespace Dapr.AspNetCore.IntegrationTest; -using Dapr.AspNetCore.IntegrationTest.App; -using Dapr.Client; +using App; +using Client; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -22,7 +22,7 @@ namespace Dapr.AspNetCore.IntegrationTest; public class AppWebApplicationFactory : WebApplicationFactory { - internal StateTestClient DaprClient { get; } = new StateTestClient(); + internal StateTestClient DaprClient { get; } = new(); protected override IHostBuilder CreateHostBuilder() { @@ -31,9 +31,9 @@ protected override IHostBuilder CreateHostBuilder() { b.SetMinimumLevel(LogLevel.None); }); - return builder.ConfigureServices((context, services) => + return builder.ConfigureServices((_, services) => { services.AddSingleton(this.DaprClient); }); } -} \ No newline at end of file +} diff --git a/test/Dapr.AspNetCore.IntegrationTest/AuthenticationTest.cs b/test/Dapr.AspNetCore.IntegrationTest/AuthenticationTest.cs index fca311342..208a17a63 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/AuthenticationTest.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/AuthenticationTest.cs @@ -24,7 +24,7 @@ namespace Dapr.AspNetCore.IntegrationTest; public class AuthenticationTest { - private JsonSerializerOptions serializerOptions = new JsonSerializerOptions + private JsonSerializerOptions serializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; @@ -32,7 +32,7 @@ public class AuthenticationTest [Fact] public async Task ValidToken_ShouldBeAuthenticatedAndAuthorized() { - using (var factory = new AppWebApplicationFactory()) + await using (var factory = new AppWebApplicationFactory()) { var userInfo = new UserInfo { @@ -44,9 +44,9 @@ public async Task ValidToken_ShouldBeAuthenticatedAndAuthorized() Content = new StringContent(JsonSerializer.Serialize(userInfo), Encoding.UTF8, "application/json") }; request.Headers.Add("Dapr-Api-Token", "abcdefg"); - var response = await httpClient.SendAsync(request); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); response.EnsureSuccessStatusCode(); - var responseContent = await response.Content.ReadAsStringAsync(); + var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); var responseUserInfo = JsonSerializer.Deserialize(responseContent, serializerOptions); responseUserInfo.Name.ShouldBe(userInfo.Name); } @@ -55,7 +55,7 @@ public async Task ValidToken_ShouldBeAuthenticatedAndAuthorized() [Fact] public async Task InvalidToken_ShouldBeUnauthorized() { - using (var factory = new AppWebApplicationFactory()) + await using (var factory = new AppWebApplicationFactory()) { var userInfo = new UserInfo { @@ -67,7 +67,7 @@ public async Task InvalidToken_ShouldBeUnauthorized() Content = new StringContent(JsonSerializer.Serialize(userInfo, serializerOptions), Encoding.UTF8, "application/json") }; request.Headers.Add("Dapr-Api-Token", "asdfgh"); - var response = await httpClient.SendAsync(request); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); response.StatusCode.ShouldBe(HttpStatusCode.Unauthorized); } diff --git a/test/Dapr.AspNetCore.IntegrationTest/CloudEventsIntegrationTest.cs b/test/Dapr.AspNetCore.IntegrationTest/CloudEventsIntegrationTest.cs index dde6751cf..1a96ee83e 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/CloudEventsIntegrationTest.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/CloudEventsIntegrationTest.cs @@ -18,13 +18,13 @@ namespace Dapr.AspNetCore.IntegrationTest; using System.Text; using System.Text.Json; using System.Threading.Tasks; -using Dapr.AspNetCore.IntegrationTest.App; +using App; using Shouldly; using Xunit; public class CloudEventsIntegrationTest { - private readonly JsonSerializerOptions options = new JsonSerializerOptions() + private readonly JsonSerializerOptions options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNameCaseInsensitive = true, @@ -33,109 +33,101 @@ public class CloudEventsIntegrationTest [Fact] public async Task CanSendEmptyStructuredCloudEvent() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/B") - { - Content = new StringContent("{}", Encoding.UTF8) - }; - request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/B") + { + Content = new StringContent("{}", Encoding.UTF8) + }; + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - } + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); } [Fact] public async Task CanSendStructuredCloudEvent() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user") - { - Content = new StringContent( - JsonSerializer.Serialize( - new + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user") + { + Content = new StringContent( + JsonSerializer.Serialize( + new + { + data = new { - data = new - { - name = "jimmy", - }, - }), - Encoding.UTF8) - }; - request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); - - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - - var userInfo = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(), this.options); - userInfo.Name.ShouldBe("jimmy"); - } + name = "jimmy", + }, + }), + Encoding.UTF8) + }; + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); + + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + + var userInfo = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(TestContext.Current.CancellationToken), this.options, TestContext.Current.CancellationToken); + userInfo.Name.ShouldBe("jimmy"); } [Fact] public async Task CanSendStructuredCloudEvent_WithContentType() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user") - { - Content = new StringContent( - JsonSerializer.Serialize( - new + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user") + { + Content = new StringContent( + JsonSerializer.Serialize( + new + { + data = new { - data = new - { - name = "jimmy", - }, - datacontenttype = "text/json", - }), - Encoding.UTF8) - }; - request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); - - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - - var userInfo = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(), this.options); - userInfo.Name.ShouldBe("jimmy"); - } + name = "jimmy", + }, + datacontenttype = "text/json", + }), + Encoding.UTF8) + }; + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); + + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + + var userInfo = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(TestContext.Current.CancellationToken), this.options, TestContext.Current.CancellationToken); + userInfo.Name.ShouldBe("jimmy"); } [Fact] public async Task CanSendStructuredCloudEvent_WithNonJsonContentType() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user-plaintext") - { - Content = new StringContent( - JsonSerializer.Serialize( - new - { - data = "jimmy \"the cool guy\" smith", - datacontenttype = "text/plain", - }), - Encoding.UTF8) - }; - request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); - - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - - var user = await response.Content.ReadAsStringAsync(); - user.ShouldBe("jimmy \"the cool guy\" smith"); - } + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user-plaintext") + { + Content = new StringContent( + JsonSerializer.Serialize( + new + { + data = "jimmy \"the cool guy\" smith", + datacontenttype = "text/plain", + }), + Encoding.UTF8) + }; + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/cloudevents+json"); + + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + + var user = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); + user.ShouldBe("jimmy \"the cool guy\" smith"); } // Yeah, I know, binary isn't a great term for this, it's what the cloudevents spec uses. @@ -144,27 +136,25 @@ public async Task CanSendStructuredCloudEvent_WithNonJsonContentType() [Fact] public async Task CanSendBinaryCloudEvent_WithContentType() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user") - { - Content = new StringContent( - JsonSerializer.Serialize( - new - { - name = "jimmy", - }), - Encoding.UTF8) - }; - request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/register-user") + { + Content = new StringContent( + JsonSerializer.Serialize( + new + { + name = "jimmy", + }), + Encoding.UTF8) + }; + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); - var userInfo = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(), this.options); - userInfo.Name.ShouldBe("jimmy"); - } + var userInfo = await JsonSerializer.DeserializeAsync(await response.Content.ReadAsStreamAsync(TestContext.Current.CancellationToken), this.options, TestContext.Current.CancellationToken); + userInfo.Name.ShouldBe("jimmy"); } -} \ No newline at end of file +} diff --git a/test/Dapr.AspNetCore.IntegrationTest/ControllerIntegrationTest.cs b/test/Dapr.AspNetCore.IntegrationTest/ControllerIntegrationTest.cs index e7315ab15..d74f2bf86 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/ControllerIntegrationTest.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/ControllerIntegrationTest.cs @@ -25,143 +25,127 @@ public class ControllerIntegrationTest [Fact] public async Task ModelBinder_CanBindFromState() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var daprClient = factory.DaprClient; + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + var daprClient = factory.DaprClient; - await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }); + await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }, cancellationToken: TestContext.Current.CancellationToken); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/controllerwithoutstateentry/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/controllerwithoutstateentry/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); - var widget = await daprClient.GetStateAsync("testStore", "test"); - widget.Count.ShouldBe(18); - } + var widget = await daprClient.GetStateAsync("testStore", "test", cancellationToken: TestContext.Current.CancellationToken); + widget.Count.ShouldBe(18); } [Fact] public async Task ModelBinder_GetFromStateEntryWithKeyPresentInStateStore_ReturnsStateValue() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var daprClient = factory.DaprClient; - - var widget = new Widget() { Size = "small", Count = 17, }; - await daprClient.SaveStateAsync("testStore", "test", widget); - var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithoutstateentry/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - var responseContent = await response.Content.ReadAsStringAsync(); - var responseWidget = JsonSerializer.Deserialize(responseContent); - responseWidget.Size.ShouldBe(widget.Size); - responseWidget.Count.ShouldBe(widget.Count); - } + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + var daprClient = factory.DaprClient; + + var widget = new Widget { Size = "small", Count = 17, }; + await daprClient.SaveStateAsync("testStore", "test", widget, cancellationToken: TestContext.Current.CancellationToken); + var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithoutstateentry/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); + var responseWidget = JsonSerializer.Deserialize(responseContent); + responseWidget.Size.ShouldBe(widget.Size); + responseWidget.Count.ShouldBe(widget.Count); } [Fact] public async Task ModelBinder_GetFromStateEntryWithKeyNotInStateStore_ReturnsNull() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - - var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithoutstateentry/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - var responseContent = await response.Content.ReadAsStringAsync(); - var responseWidget = - !string.IsNullOrWhiteSpace(responseContent) ? JsonSerializer.Deserialize(responseContent) : null; - Assert.Null(responseWidget); - } + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + + var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithoutstateentry/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); + var responseWidget = + !string.IsNullOrWhiteSpace(responseContent) ? JsonSerializer.Deserialize(responseContent) : null; + Assert.Null(responseWidget); } [Fact] public async Task ModelBinder_CanBindFromState_WithStateEntry() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var daprClient = factory.DaprClient; + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + var daprClient = factory.DaprClient; - await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }); + await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }, cancellationToken: TestContext.Current.CancellationToken); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/controllerwithstateentry/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/controllerwithstateentry/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); - var widget = await daprClient.GetStateAsync("testStore", "test"); - widget.Count.ShouldBe(18); - } + var widget = await daprClient.GetStateAsync("testStore", "test", cancellationToken: TestContext.Current.CancellationToken); + widget.Count.ShouldBe(18); } [Fact] public async Task ModelBinder_CanBindFromState_WithStateEntryAndCustomKey() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var daprClient = factory.DaprClient; + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + var daprClient = factory.DaprClient; - await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }); + await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }, cancellationToken: TestContext.Current.CancellationToken); - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/controllerwithstateentryandcustomkey/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/controllerwithstateentryandcustomkey/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); - var widget = await daprClient.GetStateAsync("testStore", "test"); - widget.Count.ShouldBe(18); - } + var widget = await daprClient.GetStateAsync("testStore", "test", cancellationToken: TestContext.Current.CancellationToken); + widget.Count.ShouldBe(18); } [Fact] public async Task ModelBinder_GetFromStateEntryWithStateEntry_WithKeyPresentInStateStore() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var daprClient = factory.DaprClient; - - var widget = new Widget() { Size = "small", Count = 17, }; - await daprClient.SaveStateAsync("testStore", "test", widget); - var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithstateentry/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - var responseContent = await response.Content.ReadAsStringAsync(); - var responseWidget = JsonSerializer.Deserialize(responseContent); - responseWidget.Size.ShouldBe(widget.Size); - responseWidget.Count.ShouldBe(widget.Count); - } + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + var daprClient = factory.DaprClient; + + var widget = new Widget() { Size = "small", Count = 17, }; + await daprClient.SaveStateAsync("testStore", "test", widget, cancellationToken: TestContext.Current.CancellationToken); + var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithstateentry/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); + var responseWidget = JsonSerializer.Deserialize(responseContent); + responseWidget.Size.ShouldBe(widget.Size); + responseWidget.Count.ShouldBe(widget.Count); } [Fact] public async Task ModelBinder_GetFromStateEntryWithStateEntry_WithKeyNotInStateStore() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - - var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithstateentry/test"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - var responseContent = await response.Content.ReadAsStringAsync(); - var responseWidget = !string.IsNullOrWhiteSpace(responseContent) ? JsonSerializer.Deserialize(responseContent) : null; - Assert.Null(responseWidget); - } + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + + var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithstateentry/test"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); + var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); + var responseWidget = !string.IsNullOrWhiteSpace(responseContent) ? JsonSerializer.Deserialize(responseContent) : null; + Assert.Null(responseWidget); } [Fact] public async Task ModelBinder_CanGetOutOfTheWayWhenTheresNoBinding() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - - var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/echo-user?name=jimmy"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); - } + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + + var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/echo-user?name=jimmy"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); } } diff --git a/test/Dapr.AspNetCore.IntegrationTest/Dapr.AspNetCore.IntegrationTest.csproj b/test/Dapr.AspNetCore.IntegrationTest/Dapr.AspNetCore.IntegrationTest.csproj index 5772612b4..8aa34e3a0 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/Dapr.AspNetCore.IntegrationTest.csproj +++ b/test/Dapr.AspNetCore.IntegrationTest/Dapr.AspNetCore.IntegrationTest.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.AspNetCore.IntegrationTest/RoutingIntegrationTest.cs b/test/Dapr.AspNetCore.IntegrationTest/RoutingIntegrationTest.cs index 321302e45..df2080c27 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/RoutingIntegrationTest.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/RoutingIntegrationTest.cs @@ -15,7 +15,7 @@ namespace Dapr.AspNetCore.IntegrationTest; using System.Net.Http; using System.Threading.Tasks; -using Dapr.AspNetCore.IntegrationTest.App; +using App; using Shouldly; using Xunit; @@ -29,14 +29,14 @@ public async Task StateClient_CanBindFromState() var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); var daprClient = factory.DaprClient; - await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }); + await daprClient.SaveStateAsync("testStore", "test", new Widget() { Size = "small", Count = 17, }, cancellationToken: TestContext.Current.CancellationToken); var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/routingwithstateentry/test"); - var response = await httpClient.SendAsync(request); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); response.EnsureSuccessStatusCode(); - var widget = await daprClient.GetStateAsync("testStore", "test"); + var widget = await daprClient.GetStateAsync("testStore", "test", cancellationToken: TestContext.Current.CancellationToken); widget.Count.ShouldBe(18); } } -} \ No newline at end of file +} diff --git a/test/Dapr.AspNetCore.IntegrationTest/StateTestClient.cs b/test/Dapr.AspNetCore.IntegrationTest/StateTestClient.cs index cd18226a2..83a18ad5a 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/StateTestClient.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/StateTestClient.cs @@ -23,7 +23,7 @@ namespace Dapr.Client; internal class StateTestClient : DaprClientGrpc { - public Dictionary State { get; } = new Dictionary(); + public Dictionary State { get; } = new(); private static readonly GrpcChannel channel = GrpcChannel.ForAddress("http://localhost"); /// @@ -118,4 +118,4 @@ public override Task DeleteStateAsync( this.State.Remove(key); return Task.CompletedTask; } -} \ No newline at end of file +} diff --git a/test/Dapr.AspNetCore.IntegrationTest/SubscribeEndpointTest.cs b/test/Dapr.AspNetCore.IntegrationTest/SubscribeEndpointTest.cs index 1f4b062f0..cc33a1b0b 100644 --- a/test/Dapr.AspNetCore.IntegrationTest/SubscribeEndpointTest.cs +++ b/test/Dapr.AspNetCore.IntegrationTest/SubscribeEndpointTest.cs @@ -27,117 +27,113 @@ public class SubscribeEndpointTest [Fact] public async Task SubscribeEndpoint_ReportsTopics() { - using (var factory = new AppWebApplicationFactory()) - { - var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); + await using var factory = new AppWebApplicationFactory(); + var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false }); - var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/dapr/subscribe"); - var response = await httpClient.SendAsync(request); - response.EnsureSuccessStatusCode(); + var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/dapr/subscribe"); + var response = await httpClient.SendAsync(request, TestContext.Current.CancellationToken); + response.EnsureSuccessStatusCode(); - using (var stream = await response.Content.ReadAsStreamAsync()) - { - var json = await JsonSerializer.DeserializeAsync(stream); + await using var stream = await response.Content.ReadAsStreamAsync(TestContext.Current.CancellationToken); + var json = await JsonSerializer.DeserializeAsync(stream, cancellationToken: TestContext.Current.CancellationToken); - json.ValueKind.ShouldBe(JsonValueKind.Array); - json.GetArrayLength().ShouldBe(18); + json.ValueKind.ShouldBe(JsonValueKind.Array); + json.GetArrayLength().ShouldBe(18); - var subscriptions = new List<(string PubsubName, string Topic, string Route, string rawPayload, - string match, string metadata, string DeadLetterTopic, string bulkSubscribeMetadata)>(); + var subscriptions = new List<(string PubsubName, string Topic, string Route, string rawPayload, + string match, string metadata, string DeadLetterTopic, string bulkSubscribeMetadata)>(); - foreach (var element in json.EnumerateArray()) - { - var pubsubName = element.GetProperty("pubsubName").GetString(); - var topic = element.GetProperty("topic").GetString(); - var rawPayload = string.Empty; - var deadLetterTopic = string.Empty; - var bulkSubscribeMetadata = string.Empty; - //JsonElement bulkSubscribeMetadata; - Dictionary originalMetadata = new Dictionary(); + foreach (var element in json.EnumerateArray()) + { + var pubsubName = element.GetProperty("pubsubName").GetString(); + var topic = element.GetProperty("topic").GetString(); + var rawPayload = string.Empty; + var deadLetterTopic = string.Empty; + var bulkSubscribeMetadata = string.Empty; + //JsonElement bulkSubscribeMetadata; + Dictionary originalMetadata = new Dictionary(); - if (element.TryGetProperty("bulkSubscribe", out var BulkSubscribeMetadata)) - { - bulkSubscribeMetadata = BulkSubscribeMetadata.ToString(); - } - if (element.TryGetProperty("deadLetterTopic", out JsonElement DeadLetterTopic)) - { - deadLetterTopic = DeadLetterTopic.GetString(); - } - if (element.TryGetProperty("metadata", out JsonElement metadata)) - { - if (metadata.TryGetProperty("rawPayload", out JsonElement rawPayloadJson)) - { - rawPayload = rawPayloadJson.GetString(); - } + if (element.TryGetProperty("bulkSubscribe", out var BulkSubscribeMetadata)) + { + bulkSubscribeMetadata = BulkSubscribeMetadata.ToString(); + } + if (element.TryGetProperty("deadLetterTopic", out JsonElement DeadLetterTopic)) + { + deadLetterTopic = DeadLetterTopic.GetString(); + } + if (element.TryGetProperty("metadata", out JsonElement metadata)) + { + if (metadata.TryGetProperty("rawPayload", out JsonElement rawPayloadJson)) + { + rawPayload = rawPayloadJson.GetString(); + } - foreach (var originalMetadataProperty in metadata.EnumerateObject().OrderBy(c => c.Name)) - { - if (!originalMetadataProperty.Name.Equals("rawPayload")) - { - originalMetadata.Add(originalMetadataProperty.Name, originalMetadataProperty.Value.GetString()); - } - } - } - var originalMetadataString = string.Empty; - if (originalMetadata.Count > 0) + foreach (var originalMetadataProperty in metadata.EnumerateObject().OrderBy(c => c.Name)) + { + if (!originalMetadataProperty.Name.Equals("rawPayload")) { - originalMetadataString = string.Join(";", originalMetadata.Select(c => $"{c.Key}={c.Value}")); + originalMetadata.Add(originalMetadataProperty.Name, originalMetadataProperty.Value.GetString()); } + } + } + var originalMetadataString = string.Empty; + if (originalMetadata.Count > 0) + { + originalMetadataString = string.Join(";", originalMetadata.Select(c => $"{c.Key}={c.Value}")); + } - if (element.TryGetProperty("route", out JsonElement route)) + if (element.TryGetProperty("route", out JsonElement route)) + { + subscriptions.Add((pubsubName, topic, route.GetString(), rawPayload, string.Empty, + originalMetadataString, deadLetterTopic, bulkSubscribeMetadata)); + } + else if (element.TryGetProperty("routes", out JsonElement routes)) + { + if (routes.TryGetProperty("rules", out JsonElement rules)) + { + foreach (var rule in rules.EnumerateArray()) { - subscriptions.Add((pubsubName, topic, route.GetString(), rawPayload, string.Empty, + var match = rule.GetProperty("match").GetString(); + var path = rule.GetProperty("path").GetString(); + subscriptions.Add((pubsubName, topic, path, rawPayload, match, originalMetadataString, deadLetterTopic, bulkSubscribeMetadata)); } - else if (element.TryGetProperty("routes", out JsonElement routes)) - { - if (routes.TryGetProperty("rules", out JsonElement rules)) - { - foreach (var rule in rules.EnumerateArray()) - { - var match = rule.GetProperty("match").GetString(); - var path = rule.GetProperty("path").GetString(); - subscriptions.Add((pubsubName, topic, path, rawPayload, match, - originalMetadataString, deadLetterTopic, bulkSubscribeMetadata)); - } - } - if (routes.TryGetProperty("default", out JsonElement defaultProperty)) - { - subscriptions.Add((pubsubName, topic, defaultProperty.GetString(), rawPayload, - string.Empty, originalMetadataString, deadLetterTopic, bulkSubscribeMetadata)); - } - } } - - subscriptions.ShouldContain(("testpubsub", "A", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("testpubsub", "A.1", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "B", "B", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("custom-pubsub", "custom-C", "C", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "register-user", "register-user", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "register-user-plaintext", "register-user-plaintext", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "D", "D", "true", string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "E", "E", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "E", "E-Critical", string.Empty, "event.type == \"critical\"", string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "E", "E-Important", string.Empty, "event.type == \"important\"", string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "F", "multiTopicAttr", string.Empty, string.Empty, string.Empty, string.Empty, - "{\"enabled\":true,\"maxMessagesCount\":100,\"maxAwaitDurationMs\":1000}")); - subscriptions.ShouldContain(("pubsub", "F.1", "multiTopicAttr", "true", string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "G", "G", string.Empty, string.Empty, string.Empty, "deadLetterTopicName", - "{\"enabled\":true,\"maxMessagesCount\":300,\"maxAwaitDurationMs\":1000}")); - subscriptions.ShouldContain(("pubsub", "splitTopicBuilder", "splitTopics", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "splitTopicAttr", "splitTopics", "true", string.Empty, string.Empty, string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "metadata", "multiMetadataTopicAttr", string.Empty, string.Empty, "n1=v1;n2=v2,v3", string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "metadata.1", "multiMetadataTopicAttr", "true", string.Empty, "n1=v1", string.Empty, - "{\"enabled\":true,\"maxMessagesCount\":500,\"maxAwaitDurationMs\":2000}")); - subscriptions.ShouldContain(("pubsub", "splitMetadataTopicBuilder", "splitMetadataTopics", string.Empty, string.Empty, "n1=v1;n2=v1", string.Empty, String.Empty)); - subscriptions.ShouldContain(("pubsub", "metadataseparatorbyemptystring", "topicmetadataseparatorattrbyemptystring", string.Empty, string.Empty, "n1=v1,", string.Empty, String.Empty)); - // Test priority route sorting - var eTopic = subscriptions.FindAll(e => e.Topic == "E"); - eTopic.Count.ShouldBe(3); - eTopic[0].Route.ShouldBe("E-Critical"); - eTopic[1].Route.ShouldBe("E-Important"); - eTopic[2].Route.ShouldBe("E"); + if (routes.TryGetProperty("default", out JsonElement defaultProperty)) + { + subscriptions.Add((pubsubName, topic, defaultProperty.GetString(), rawPayload, + string.Empty, originalMetadataString, deadLetterTopic, bulkSubscribeMetadata)); + } } } + + subscriptions.ShouldContain(("testpubsub", "A", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("testpubsub", "A.1", "topic-a", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "B", "B", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("custom-pubsub", "custom-C", "C", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "register-user", "register-user", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "register-user-plaintext", "register-user-plaintext", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "D", "D", "true", string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "E", "E", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "E", "E-Critical", string.Empty, "event.type == \"critical\"", string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "E", "E-Important", string.Empty, "event.type == \"important\"", string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "F", "multiTopicAttr", string.Empty, string.Empty, string.Empty, string.Empty, + "{\"enabled\":true,\"maxMessagesCount\":100,\"maxAwaitDurationMs\":1000}")); + subscriptions.ShouldContain(("pubsub", "F.1", "multiTopicAttr", "true", string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "G", "G", string.Empty, string.Empty, string.Empty, "deadLetterTopicName", + "{\"enabled\":true,\"maxMessagesCount\":300,\"maxAwaitDurationMs\":1000}")); + subscriptions.ShouldContain(("pubsub", "splitTopicBuilder", "splitTopics", string.Empty, string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "splitTopicAttr", "splitTopics", "true", string.Empty, string.Empty, string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "metadata", "multiMetadataTopicAttr", string.Empty, string.Empty, "n1=v1;n2=v2,v3", string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "metadata.1", "multiMetadataTopicAttr", "true", string.Empty, "n1=v1", string.Empty, + "{\"enabled\":true,\"maxMessagesCount\":500,\"maxAwaitDurationMs\":2000}")); + subscriptions.ShouldContain(("pubsub", "splitMetadataTopicBuilder", "splitMetadataTopics", string.Empty, string.Empty, "n1=v1;n2=v1", string.Empty, String.Empty)); + subscriptions.ShouldContain(("pubsub", "metadataseparatorbyemptystring", "topicmetadataseparatorattrbyemptystring", string.Empty, string.Empty, "n1=v1,", string.Empty, String.Empty)); + // Test priority route sorting + var eTopic = subscriptions.FindAll(e => e.Topic == "E"); + eTopic.Count.ShouldBe(3); + eTopic[0].Route.ShouldBe("E-Critical"); + eTopic[1].Route.ShouldBe("E-Important"); + eTopic[2].Route.ShouldBe("E"); } } diff --git a/test/Dapr.AspNetCore.Test/Dapr.AspNetCore.Test.csproj b/test/Dapr.AspNetCore.Test/Dapr.AspNetCore.Test.csproj index b25fcec6e..659306780 100644 --- a/test/Dapr.AspNetCore.Test/Dapr.AspNetCore.Test.csproj +++ b/test/Dapr.AspNetCore.Test/Dapr.AspNetCore.Test.csproj @@ -7,7 +7,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Client.Test/BulkPublishEventApiTest.cs b/test/Dapr.Client.Test/BulkPublishEventApiTest.cs index 2a35dc65a..746138456 100644 --- a/test/Dapr.Client.Test/BulkPublishEventApiTest.cs +++ b/test/Dapr.Client.Test/BulkPublishEventApiTest.cs @@ -303,8 +303,7 @@ public async Task BulkPublishEventAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.BulkPublishEventAsync(TestPubsubName, TestTopicName, - bulkPublishData); + await client.DaprClient.BulkPublishEventAsync(TestPubsubName, TestTopicName, bulkPublishData, cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -387,7 +386,10 @@ public async Task BulkPublishEventAsync_CanPublishTopicWithByteArrayEvents() // Create Response & Respond var response = new Autogenerated.BulkPublishResponse { - FailedEntries = { } + FailedEntries = + { + Capacity = 0 + } }; var bulkPublishResponse = await request.CompleteWithMessageAsync(response); diff --git a/test/Dapr.Client.Test/Dapr.Client.Test.csproj b/test/Dapr.Client.Test/Dapr.Client.Test.csproj index 17105cd16..42ff3020c 100644 --- a/test/Dapr.Client.Test/Dapr.Client.Test.csproj +++ b/test/Dapr.Client.Test/Dapr.Client.Test.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs index 1c0e40288..a083b7ebe 100644 --- a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs +++ b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodAsync.cs @@ -640,7 +640,7 @@ public async Task CreateInvokeMethodRequest_WithData_CreatesJsonContent() Assert.Same(data, content.Value); // the best way to verify the usage of the correct settings object - var actual = await content.ReadFromJsonAsync(this.jsonSerializerOptions); + var actual = await content.ReadFromJsonAsync(this.jsonSerializerOptions, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal(data.Color, actual.Color); } @@ -666,7 +666,7 @@ public async Task CreateInvokeMethodRequest_WithData_CreatesJsonContentWithQuery Assert.Same(data, content.Value); // the best way to verify the usage of the correct settings object - var actual = await content.ReadFromJsonAsync(this.jsonSerializerOptions); + var actual = await content.ReadFromJsonAsync(this.jsonSerializerOptions, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal(data.Color, actual.Color); } @@ -753,7 +753,7 @@ public async Task InvokeMethodWithResponseAsync_PreventsNonDaprRequest() var request = new HttpRequestMessage(HttpMethod.Get, "https://example.com"); var ex = await Assert.ThrowsAsync(async () => { - await client.InnerClient.InvokeMethodWithResponseAsync(request); + await client.InnerClient.InvokeMethodWithResponseAsync(request, TestContext.Current.CancellationToken); }); Assert.Equal("The provided request URI is not a Dapr service invocation URI.", ex.Message); diff --git a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs index 2a12f0bb6..459174b93 100644 --- a/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs +++ b/test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs @@ -109,7 +109,7 @@ await client.Call() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.InvokeMethodGrpcAsync("test", "test", new Request() { RequestParameter = "Hello " }); + await client.DaprClient.InvokeMethodGrpcAsync("test", "test", new Request() { RequestParameter = "Hello " }, TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -175,7 +175,7 @@ await client.Call() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.InvokeMethodGrpcAsync("test", "test"); + await client.DaprClient.InvokeMethodGrpcAsync("test", "test", TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -234,7 +234,7 @@ await client.Call() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.InvokeMethodGrpcAsync("test", "test", new Request() { RequestParameter = "Hello " }); + await client.DaprClient.InvokeMethodGrpcAsync("test", "test", new Request() { RequestParameter = "Hello " }, TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -316,7 +316,7 @@ public async Task InvokeMethodGrpcAsync_AppCallback_SayHello() var request = new Request() { RequestParameter = "Look, I was invoked!" }; - var response = await daprClient.InvokeMethodGrpcAsync("test", "SayHello", request); + var response = await daprClient.InvokeMethodGrpcAsync("test", "SayHello", request, TestContext.Current.CancellationToken); response.Name.ShouldBe("Hello Look, I was invoked!"); } @@ -337,7 +337,7 @@ public async Task InvokeMethodGrpcAsync_AppCallback_RepeatedField() testRun.Tests.Add(new TestCase() { Name = "test2" }); testRun.Tests.Add(new TestCase() { Name = "test3" }); - var response = await daprClient.InvokeMethodGrpcAsync("test", "TestRun", testRun); + var response = await daprClient.InvokeMethodGrpcAsync("test", "TestRun", testRun, TestContext.Current.CancellationToken); response.Tests.Count.ShouldBe(3); response.Tests[0].Name.ShouldBe("test1"); @@ -358,7 +358,7 @@ public async Task InvokeMethodGrpcAsync_AppCallback_UnexpectedMethod() var request = new Request() { RequestParameter = "Look, I was invoked!" }; - var response = await daprClient.InvokeMethodGrpcAsync("test", "not-existing", request); + var response = await daprClient.InvokeMethodGrpcAsync("test", "not-existing", request, TestContext.Current.CancellationToken); response.Name.ShouldBe("unexpected"); } @@ -382,7 +382,7 @@ public async Task GetMetadataAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.GetMetadataAsync(default); + await client.DaprClient.GetMetadataAsync(TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -395,10 +395,7 @@ public async Task GetMetadataAsync_WithReturnTypeAndData() c.UseJsonSerializationOptions(this.jsonSerializerOptions); }); - var request = await client.CaptureGrpcRequestAsync(async daprClient => - { - return await daprClient.GetMetadataAsync(default); - }); + var request = await client.CaptureGrpcRequestAsync(async daprClient => await daprClient.GetMetadataAsync(default)); // Create Response & Respond @@ -437,7 +434,7 @@ public async Task SetMetadataAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.SetMetadataAsync("testName", "", default); + await client.DaprClient.SetMetadataAsync("testName", "", TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } diff --git a/test/Dapr.Client.Test/DistributedLockApiTest.cs b/test/Dapr.Client.Test/DistributedLockApiTest.cs index ad5775a98..4c9f260a1 100644 --- a/test/Dapr.Client.Test/DistributedLockApiTest.cs +++ b/test/Dapr.Client.Test/DistributedLockApiTest.cs @@ -19,21 +19,18 @@ namespace Dapr.Client.Test; -[System.Obsolete] +[Obsolete] public class DistributedLockApiTest { [Fact] public async Task TryLockAsync_WithAllValues_ValidateRequest() { await using var client = TestClient.CreateForDaprClient(); - string storeName = "redis"; - string resourceId = "resourceId"; - string lockOwner = "owner1"; - Int32 expiryInSeconds = 1000; - var request = await client.CaptureGrpcRequestAsync(async daprClient => - { - return await daprClient.Lock(storeName, resourceId, lockOwner, expiryInSeconds); - }); + const string storeName = "redis"; + const string resourceId = "resourceId"; + const string lockOwner = "owner1"; + const int expiryInSeconds = 1000; + var request = await client.CaptureGrpcRequestAsync(async daprClient => await daprClient.Lock(storeName, resourceId, lockOwner, expiryInSeconds)); // Get Request and validate var envelope = await request.GetRequestEnvelopeAsync(); @@ -55,12 +52,12 @@ public async Task TryLockAsync_WithAllValues_ValidateRequest() public async Task TryLockAsync_WithAllValues_ArgumentVerifierException() { var client = new DaprClientBuilder().Build(); - string storeName = "redis"; - string resourceId = "resourceId"; - string lockOwner = "owner1"; - Int32 expiryInSeconds = 0; + const string storeName = "redis"; + const string resourceId = "resourceId"; + const string lockOwner = "owner1"; + const int expiryInSeconds = 0; // Get response and validate - await Assert.ThrowsAsync(async () => await client.Lock(storeName, resourceId, lockOwner, expiryInSeconds)); + await Assert.ThrowsAsync(async () => await client.Lock(storeName, resourceId, lockOwner, expiryInSeconds, TestContext.Current.CancellationToken)); } //Tests For Unlock API @@ -69,14 +66,11 @@ public async Task TryLockAsync_WithAllValues_ArgumentVerifierException() public async Task UnLockAsync_WithAllValues_ValidateRequest() { await using var client = TestClient.CreateForDaprClient(); - string storeName = "redis"; - string resourceId = "resourceId"; - string lockOwner = "owner1"; + const string storeName = "redis"; + const string resourceId = "resourceId"; + const string lockOwner = "owner1"; - var request = await client.CaptureGrpcRequestAsync(async daprClient => - { - return await daprClient.Unlock(storeName, resourceId, lockOwner); - }); + var request = await client.CaptureGrpcRequestAsync(async daprClient => await daprClient.Unlock(storeName, resourceId, lockOwner)); // Get Request and validate var envelope = await request.GetRequestEnvelopeAsync(); @@ -92,4 +86,4 @@ public async Task UnLockAsync_WithAllValues_ValidateRequest() var domainResponse = await request.CompleteWithMessageAsync(invokeResponse); domainResponse.status.ShouldBe(LockStatus.LockDoesNotExist); } -} \ No newline at end of file +} diff --git a/test/Dapr.Client.Test/InvocationHandlerTests.cs b/test/Dapr.Client.Test/InvocationHandlerTests.cs index e6cfc2231..de085b8c9 100644 --- a/test/Dapr.Client.Test/InvocationHandlerTests.cs +++ b/test/Dapr.Client.Test/InvocationHandlerTests.cs @@ -126,7 +126,7 @@ public void TryRewriteUri_WithNoAppId_RewritesUriToDaprInvoke(string? appId, str }; Assert.True(handler.TryRewriteUri(new Uri(uri), out var rewritten)); - Assert.Equal(expected, rewritten!.OriginalString); + Assert.Equal(expected, rewritten.OriginalString); } [Fact] @@ -135,7 +135,7 @@ public async Task SendAsync_InvalidNotSetUri_ThrowsException() var handler = new InvocationHandler(); var ex = await Assert.ThrowsAsync(async () => { - await CallSendAsync(handler, new HttpRequestMessage() { }); // No URI set + await InvocationHandlerTests.CallSendAsync(handler, new HttpRequestMessage() { }, TestContext.Current.CancellationToken); // No URI set }); Assert.Contains("The request URI '' is not a valid Dapr service invocation destination.", ex.Message); @@ -156,7 +156,7 @@ public async Task SendAsync_RewritesUri() }; var request = new HttpRequestMessage(HttpMethod.Post, uri); - await CallSendAsync(handler, request); + await InvocationHandlerTests.CallSendAsync(handler, request, TestContext.Current.CancellationToken); Assert.Equal("https://localhost:5000/v1.0/invoke/bank/method/accounts/17?", capture.RequestUri?.OriginalString); Assert.Null(capture.DaprApiToken); @@ -181,7 +181,7 @@ public async Task SendAsync_RewritesUri_AndAppId() }; var request = new HttpRequestMessage(HttpMethod.Post, uri); - await CallSendAsync(handler, request); + await InvocationHandlerTests.CallSendAsync(handler, request, TestContext.Current.CancellationToken); Assert.Equal("https://localhost:5000/v1.0/invoke/Bank/method/accounts/17?", capture.RequestUri?.OriginalString); Assert.Null(capture.DaprApiToken); @@ -205,7 +205,7 @@ public async Task SendAsync_RewritesUri_AndAddsApiToken() }; var request = new HttpRequestMessage(HttpMethod.Post, uri); - await CallSendAsync(handler, request); + await InvocationHandlerTests.CallSendAsync(handler, request, TestContext.Current.CancellationToken); Assert.Equal("https://localhost:5000/v1.0/invoke/bank/method/accounts/17?", capture.RequestUri?.OriginalString); Assert.Equal("super-duper-secure", capture.DaprApiToken); @@ -214,7 +214,7 @@ public async Task SendAsync_RewritesUri_AndAddsApiToken() Assert.False(request.Headers.TryGetValues("dapr-api-token", out _)); } - private async Task CallSendAsync(InvocationHandler handler, HttpRequestMessage message, CancellationToken cancellationToken = default) + private static async Task CallSendAsync(InvocationHandler handler, HttpRequestMessage message, CancellationToken cancellationToken = default) { // SendAsync is protected, can't call it directly. var method = handler.GetType().GetMethod("SendAsync", BindingFlags.Instance | BindingFlags.NonPublic); @@ -222,7 +222,7 @@ private async Task CallSendAsync(InvocationHandler handler, try { - return await (Task)method!.Invoke(handler, new object[] { message, cancellationToken, })!; + return await (Task)method!.Invoke(handler, [message, cancellationToken])!; } catch (TargetInvocationException tie) // reflection always adds an extra layer of exceptions. { @@ -247,4 +247,4 @@ protected override Task SendAsync(HttpRequestMessage reques return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); } } -} \ No newline at end of file +} diff --git a/test/Dapr.Client.Test/InvokeBindingApiTest.cs b/test/Dapr.Client.Test/InvokeBindingApiTest.cs index 2e0b50253..598524a6b 100644 --- a/test/Dapr.Client.Test/InvokeBindingApiTest.cs +++ b/test/Dapr.Client.Test/InvokeBindingApiTest.cs @@ -191,7 +191,7 @@ public async Task InvokeBindingAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.InvokeBindingAsync("test", "test", new InvokeRequest() { RequestParameter = "Hello " }); + await client.DaprClient.InvokeBindingAsync("test", "test", new InvokeRequest() { RequestParameter = "Hello " }, cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -283,7 +283,7 @@ public async Task InvokeBindingRequest_WithBindingNull_CheckException() var ex = await Assert.ThrowsAsync(async () => { - await client.InnerClient.InvokeBindingAsync(null, "operation", null); + await client.InnerClient.InvokeBindingAsync(null, "operation", null, cancellationToken: TestContext.Current.CancellationToken); }); Assert.IsType(ex); } @@ -295,7 +295,7 @@ public async Task InvokeBindingRequest_WithOperationNull_CheckException() var ex = await Assert.ThrowsAsync(async () => { - await client.InnerClient.InvokeBindingAsync("binding", null, null); + await client.InnerClient.InvokeBindingAsync("binding", null, null, cancellationToken: TestContext.Current.CancellationToken); }); Assert.IsType(ex); } diff --git a/test/Dapr.Client.Test/PublishEventApiTest.cs b/test/Dapr.Client.Test/PublishEventApiTest.cs index 7130fa4de..a852ddce8 100644 --- a/test/Dapr.Client.Test/PublishEventApiTest.cs +++ b/test/Dapr.Client.Test/PublishEventApiTest.cs @@ -263,7 +263,7 @@ public async Task PublishEventAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.PublishEventAsync("test", "test"); + await client.DaprClient.PublishEventAsync("test", "test", TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -311,4 +311,4 @@ private enum WidgetColor Green, Yellow } -} \ No newline at end of file +} diff --git a/test/Dapr.Client.Test/SecretApiTest.cs b/test/Dapr.Client.Test/SecretApiTest.cs index 79dac62c4..3884b63ec 100644 --- a/test/Dapr.Client.Test/SecretApiTest.cs +++ b/test/Dapr.Client.Test/SecretApiTest.cs @@ -197,7 +197,7 @@ public async Task GetSecretAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.GetSecretAsync("test", "test"); + await client.DaprClient.GetSecretAsync("test", "test", cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -323,7 +323,7 @@ public async Task GetBulkSecretAsync_WrapsRpcException() { var client = new MockClient(); - var rpcStatus = new Grpc.Core.Status(StatusCode.Internal, "not gonna work"); + var rpcStatus = new Status(StatusCode.Internal, "not gonna work"); var rpcException = new RpcException(rpcStatus, new Metadata(), "not gonna work"); // Setup the mock client to throw an Rpc Exception with the expected details info @@ -333,7 +333,7 @@ public async Task GetBulkSecretAsync_WrapsRpcException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.GetBulkSecretAsync("test"); + await client.DaprClient.GetBulkSecretAsync("test", cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -358,4 +358,4 @@ private async Task SendBulkResponseWithSecrets(Dictionary< return await request.CompleteWithMessageAsync(getBulkSecretResponse); } -} \ No newline at end of file +} diff --git a/test/Dapr.Client.Test/StateApiTest.cs b/test/Dapr.Client.Test/StateApiTest.cs index 5e9b5e240..f5079caf9 100644 --- a/test/Dapr.Client.Test/StateApiTest.cs +++ b/test/Dapr.Client.Test/StateApiTest.cs @@ -796,7 +796,7 @@ public async Task TrySaveStateAsync_ValidateNonETagErrorThrowsException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.TrySaveStateAsync("test", "test", "testValue", "someETag"); + await client.DaprClient.TrySaveStateAsync("test", "test", "testValue", "someETag", cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -815,7 +815,7 @@ await client.CallStateApi() .Setup(m => m.SaveStateAsync(It.IsAny(), It.IsAny())) .Throws(rpcException); - var operationResult = await client.DaprClient.TrySaveStateAsync("testStore", "test", "testValue", "invalidETag"); + var operationResult = await client.DaprClient.TrySaveStateAsync("testStore", "test", "testValue", "invalidETag", cancellationToken: TestContext.Current.CancellationToken); Assert.False(operationResult); } @@ -842,7 +842,7 @@ public async Task TrySaveStateAsync_EmptyEtagDoesNotThrow() .Setup(m => m.SaveStateAsync(It.IsAny(), It.IsAny())) .Returns(response); - var result = await client.DaprClient.TrySaveStateAsync("test", "test", "testValue", ""); + var result = await client.DaprClient.TrySaveStateAsync("test", "test", "testValue", "", cancellationToken: TestContext.Current.CancellationToken); Assert.True(result); } @@ -863,7 +863,7 @@ await client.CallStateApi() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.TryDeleteStateAsync("test", "test", "badEtag"); + await client.DaprClient.TryDeleteStateAsync("test", "test", "badEtag", cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -891,7 +891,7 @@ public async Task TryDeleteStateAsync_EmptyEtagDoesNotThrow() .Setup(m => m.DeleteStateAsync(It.IsAny(), It.IsAny())) .Returns(response); - var result = await client.DaprClient.TryDeleteStateAsync("test", "test", ""); + var result = await client.DaprClient.TryDeleteStateAsync("test", "test", "", cancellationToken: TestContext.Current.CancellationToken); Assert.True(result); } @@ -909,7 +909,7 @@ await client.CallStateApi() .Setup(m => m.DeleteStateAsync(It.IsAny(), It.IsAny())) .Throws(rpcException); - var operationResult = await client.DaprClient.TryDeleteStateAsync("test", "test", "invalidETag"); + var operationResult = await client.DaprClient.TryDeleteStateAsync("test", "test", "invalidETag", cancellationToken: TestContext.Current.CancellationToken); Assert.False(operationResult); } @@ -1297,7 +1297,7 @@ public async Task TrySaveByteStateAsync_ValidateNonETagErrorThrowsException() var ex = await Assert.ThrowsAsync(async () => { - await client.DaprClient.TrySaveByteStateAsync("test", "test", stateBytes.AsMemory(), "someETag"); + await client.DaprClient.TrySaveByteStateAsync("test", "test", stateBytes.AsMemory(), "someETag", cancellationToken: TestContext.Current.CancellationToken); }); Assert.Same(rpcException, ex.InnerException); } @@ -1317,7 +1317,7 @@ public async Task TrySaveByteStateAsync_ValidateETagRelatedExceptionReturnsFalse .Setup(m => m.SaveStateAsync(It.IsAny(), It.IsAny())) .Throws(rpcException); - var operationResult = await client.DaprClient.TrySaveByteStateAsync("testStore", "test", stateBytes.AsMemory(), "invalidETag"); + var operationResult = await client.DaprClient.TrySaveByteStateAsync("testStore", "test", stateBytes.AsMemory(), "invalidETag", cancellationToken: TestContext.Current.CancellationToken); Assert.False(operationResult); } @@ -1347,7 +1347,7 @@ public async Task TrySaveByteStateAsync_EmptyEtagDoesNotThrow() .Setup(m => m.SaveStateAsync(It.IsAny(), It.IsAny())) .Returns(response); - var result = await client.DaprClient.TrySaveByteStateAsync("test", "test", stateBytes.AsMemory(), ""); + var result = await client.DaprClient.TrySaveByteStateAsync("test", "test", stateBytes.AsMemory(), "", cancellationToken: TestContext.Current.CancellationToken); Assert.True(result); } [Fact] diff --git a/test/Dapr.Common.Test/Dapr.Common.Test.csproj b/test/Dapr.Common.Test/Dapr.Common.Test.csproj index ed1543904..e73e6bc80 100644 --- a/test/Dapr.Common.Test/Dapr.Common.Test.csproj +++ b/test/Dapr.Common.Test/Dapr.Common.Test.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Cryptography.Test/Dapr.Cryptography.Test.csproj b/test/Dapr.Cryptography.Test/Dapr.Cryptography.Test.csproj index 2c6c0dcde..1d8ab8dac 100644 --- a/test/Dapr.Cryptography.Test/Dapr.Cryptography.Test.csproj +++ b/test/Dapr.Cryptography.Test/Dapr.Cryptography.Test.csproj @@ -13,8 +13,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.E2E.Test.Actors.Generators/Clients/GeneratedClientTests.cs b/test/Dapr.E2E.Test.Actors.Generators/Clients/GeneratedClientTests.cs index a089a2e82..1394c1bb4 100644 --- a/test/Dapr.E2E.Test.Actors.Generators/Clients/GeneratedClientTests.cs +++ b/test/Dapr.E2E.Test.Actors.Generators/Clients/GeneratedClientTests.cs @@ -13,7 +13,6 @@ using Dapr.Actors; using Dapr.Actors.Client; -using Xunit.Abstractions; namespace Dapr.E2E.Test.Actors.Generators.Clients; diff --git a/test/Dapr.E2E.Test.Actors.Generators/Dapr.E2E.Test.Actors.Generators.csproj b/test/Dapr.E2E.Test.Actors.Generators/Dapr.E2E.Test.Actors.Generators.csproj index cb375af01..99982a4fb 100644 --- a/test/Dapr.E2E.Test.Actors.Generators/Dapr.E2E.Test.Actors.Generators.csproj +++ b/test/Dapr.E2E.Test.Actors.Generators/Dapr.E2E.Test.Actors.Generators.csproj @@ -1,6 +1,7 @@ + Library enable enable @@ -11,7 +12,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Dapr.E2E.Test.Actors.Generators/XUnitLoggingProvider.cs b/test/Dapr.E2E.Test.Actors.Generators/XUnitLoggingProvider.cs index 641d66d80..669992c10 100644 --- a/test/Dapr.E2E.Test.Actors.Generators/XUnitLoggingProvider.cs +++ b/test/Dapr.E2E.Test.Actors.Generators/XUnitLoggingProvider.cs @@ -11,8 +11,6 @@ // limitations under the License. // ------------------------------------------------------------------------ -using Xunit.Abstractions; - namespace Dapr.E2E.Test.Actors.Generators; internal sealed class XUnitLoggingProvider : ILoggerProvider @@ -73,4 +71,4 @@ public void Dispose() { } } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test.Actors/Dapr.E2E.Test.Actors.csproj b/test/Dapr.E2E.Test.Actors/Dapr.E2E.Test.Actors.csproj index 56ab3d222..e38785730 100644 --- a/test/Dapr.E2E.Test.Actors/Dapr.E2E.Test.Actors.csproj +++ b/test/Dapr.E2E.Test.Actors/Dapr.E2E.Test.Actors.csproj @@ -1,5 +1,9 @@ + + Library + + diff --git a/test/Dapr.E2E.Test/ActorRuntimeChecker.cs b/test/Dapr.E2E.Test/ActorRuntimeChecker.cs index 071517561..e657a9a49 100644 --- a/test/Dapr.E2E.Test/ActorRuntimeChecker.cs +++ b/test/Dapr.E2E.Test/ActorRuntimeChecker.cs @@ -15,7 +15,7 @@ using System.Threading; using System.Threading.Tasks; using Dapr.E2E.Test.Actors; -using Xunit.Abstractions; +using Xunit; namespace Dapr.E2E.Test; diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.CustomSerializerTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.CustomSerializerTests.cs index d0f12315a..3c0e94210 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.CustomSerializerTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.CustomSerializerTests.cs @@ -21,7 +21,6 @@ namespace Dapr.E2E.Test; using Dapr.Actors.Client; using Dapr.E2E.Test.Actors; using Xunit; -using Xunit.Abstractions; public class CustomSerializerTests : DaprTestAppLifecycle { @@ -111,4 +110,4 @@ public async Task ActorCanSupportCustomSerializerAndCallMoreThenOneDefinedMethod Assert.Equal(payload, result); } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.ExceptionTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.ExceptionTests.cs index ee4645dca..d3e8b6490 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.ExceptionTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.ExceptionTests.cs @@ -19,7 +19,7 @@ namespace Dapr.E2E.Test; using Dapr.Actors; using Dapr.E2E.Test.Actors.ExceptionTesting; using Xunit; -public partial class E2ETests : IAsyncLifetime +public partial class E2ETests { [Fact] public async Task ActorCanProvideExceptionDetails() @@ -33,4 +33,4 @@ public async Task ActorCanProvideExceptionDetails() Assert.Contains("ExceptionExample", ex.Message); Assert.Contains("32", ex.Message); } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.ReentrantTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.ReentrantTests.cs index 3b31e766f..b8f63e466 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.ReentrantTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.ReentrantTests.cs @@ -21,11 +21,10 @@ namespace Dapr.E2E.Test; using Dapr.Actors.Client; using Dapr.E2E.Test.Actors.Reentrancy; using Xunit; -using Xunit.Abstractions; public class ReentrantTests : DaprTestAppLifecycle { - private static readonly int NumCalls = 10; + private const int NumCalls = 10; private readonly Lazy proxyFactory; private IActorProxyFactory ProxyFactory => this.HttpEndpoint == null ? null : this.proxyFactory.Value; @@ -75,4 +74,4 @@ public async Task ActorCanPerformReentrantCalls() } } } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.Regression762Tests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.Regression762Tests.cs index c4aa669b7..ea12da644 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.Regression762Tests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.Regression762Tests.cs @@ -20,7 +20,7 @@ namespace Dapr.E2E.Test; -public partial class E2ETests : IAsyncLifetime +public partial class E2ETests { [Fact] public async Task ActorSuccessfullyClearsStateAfterErrorWithRemoting() @@ -97,19 +97,19 @@ public async Task ActorSuccessfullyClearsStateAfterErrorWithoutRemoting() }; // We attempt to delete it on the unlikely chance it's already there. - await proxy.InvokeMethodAsync("RemoveState", throwingCall.Key); + await proxy.InvokeMethodAsync("RemoveState", throwingCall.Key, TestContext.Current.CancellationToken); // Initiate a call that will set the state, then throw. - await Assert.ThrowsAsync(async () => await proxy.InvokeMethodAsync("SaveState", throwingCall)); + await Assert.ThrowsAsync(async () => await proxy.InvokeMethodAsync("SaveState", throwingCall, TestContext.Current.CancellationToken)); // Save the state and assert that the old value was not persisted. - await proxy.InvokeMethodAsync("SaveState", savingCall); - var errorResp = await proxy.InvokeMethodAsync("GetState", key); + await proxy.InvokeMethodAsync("SaveState", savingCall, TestContext.Current.CancellationToken); + var errorResp = await proxy.InvokeMethodAsync("GetState", key, TestContext.Current.CancellationToken); Assert.Equal(string.Empty, errorResp); // Persist normally and ensure it works. - await proxy.InvokeMethodAsync("SaveState", setCall); - var resp = await proxy.InvokeMethodAsync("GetState", key); + await proxy.InvokeMethodAsync("SaveState", setCall, TestContext.Current.CancellationToken); + var resp = await proxy.InvokeMethodAsync("GetState", key, TestContext.Current.CancellationToken); Assert.Equal("Real value", resp); } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.ReminderTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.ReminderTests.cs index 378d96d26..89b62e585 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.ReminderTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.ReminderTests.cs @@ -20,7 +20,7 @@ namespace Dapr.E2E.Test; using Dapr.E2E.Test.Actors.Reminders; using Xunit; -public partial class E2ETests : IAsyncLifetime +public partial class E2ETests { [Fact] public async Task ActorCanStartAndStopReminder() @@ -115,7 +115,7 @@ public async Task ActorCanStartReminderWithRepetitions() await proxy.StartReminderWithRepetitions(repetitions); var start = DateTime.Now; - await Task.Delay(TimeSpan.FromSeconds(7)); + await Task.Delay(TimeSpan.FromSeconds(7), TestContext.Current.CancellationToken); var state = await proxy.GetState(); @@ -141,7 +141,7 @@ public async Task ActorCanStartReminderWithTtlAndRepetitions() await proxy.StartReminderWithTtlAndRepetitions(TimeSpan.FromSeconds(5), repetitions); var start = DateTime.Now; - await Task.Delay(TimeSpan.FromSeconds(5)); + await Task.Delay(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); var state = await proxy.GetState(); @@ -167,7 +167,7 @@ public async Task ActorCanStartReminderWithTtl() // Record the start time and wait for longer than the reminder should exist for. var start = DateTime.Now; - await Task.Delay(TimeSpan.FromSeconds(5)); + await Task.Delay(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); var state = await proxy.GetState(); @@ -175,4 +175,4 @@ public async Task ActorCanStartReminderWithTtl() Assert.True(state.Timestamp.Subtract(start) > TimeSpan.Zero, "Reminder may not have triggered."); Assert.True(DateTime.Now.Subtract(state.Timestamp) > TimeSpan.FromSeconds(1), $"Reminder triggered too recently. {DateTime.Now} - {state.Timestamp}"); } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.StateTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.StateTests.cs index 6c2a5023c..3fd753cb1 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.StateTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.StateTests.cs @@ -19,7 +19,7 @@ namespace Dapr.E2E.Test; using Dapr.E2E.Test.Actors.State; using Xunit; -public partial class E2ETests : IAsyncLifetime +public partial class E2ETests { [Fact] public async Task ActorCanSaveStateWithTTL() @@ -34,7 +34,7 @@ public async Task ActorCanSaveStateWithTTL() var resp = await proxy.GetState("key"); Assert.Equal("value", resp); - await Task.Delay(TimeSpan.FromSeconds(2.5)); + await Task.Delay(TimeSpan.FromSeconds(2.5), cts.Token); // Assert key no longer exists. await Assert.ThrowsAsync(() => proxy.GetState("key")); @@ -60,7 +60,7 @@ public async Task ActorStateTTLOverridesExisting() Assert.Equal("value", resp); // TLL 2 seconds - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), cts.Token); resp = await proxy.GetState("key"); Assert.Equal("value", resp); @@ -68,12 +68,12 @@ public async Task ActorStateTTLOverridesExisting() await proxy.SetState("key", "value", TimeSpan.FromSeconds(4)); // TLL 2 seconds - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), cts.Token); resp = await proxy.GetState("key"); Assert.Equal("value", resp); // TLL 0 seconds - await Task.Delay(TimeSpan.FromSeconds(2.5)); + await Task.Delay(TimeSpan.FromSeconds(2.5), cts.Token); // Assert key no longer exists. await Assert.ThrowsAsync(() => proxy.GetState("key")); @@ -90,11 +90,11 @@ public async Task ActorStateTTLRemoveTTL() // Can remove TTL and then add again await proxy.SetState("key", "value", TimeSpan.FromSeconds(2)); await proxy.SetState("key", "value", null); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), cts.Token); var resp = await proxy.GetState("key"); Assert.Equal("value", resp); await proxy.SetState("key", "value", TimeSpan.FromSeconds(2)); - await Task.Delay(TimeSpan.FromSeconds(2.5)); + await Task.Delay(TimeSpan.FromSeconds(2.5), cts.Token); await Assert.ThrowsAsync(() => proxy.GetState("key")); } @@ -114,8 +114,8 @@ public async Task ActorStateBetweenProxies() resp = await proxy2.GetState("key"); Assert.Equal("value", resp); - await Task.Delay(TimeSpan.FromSeconds(2.5)); + await Task.Delay(TimeSpan.FromSeconds(2.5), cts.Token); await Assert.ThrowsAsync(() => proxy1.GetState("key")); await Assert.ThrowsAsync(() => proxy2.GetState("key")); } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.TimerTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.TimerTests.cs index 61e16d8d7..ff92282ab 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.TimerTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.TimerTests.cs @@ -19,7 +19,7 @@ namespace Dapr.E2E.Test; using Dapr.E2E.Test.Actors.Timers; using Xunit; -public partial class E2ETests : IAsyncLifetime +public partial class E2ETests { [Fact] public async Task ActorCanStartAndStopTimer() @@ -62,7 +62,7 @@ public async Task ActorCanStartTimerWithTtl() // Record the start time and wait for longer than the reminder should exist for. var start = DateTime.Now; - await Task.Delay(TimeSpan.FromSeconds(5)); + await Task.Delay(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); var state = await proxy.GetState(); @@ -70,4 +70,4 @@ public async Task ActorCanStartTimerWithTtl() Assert.True(state.Timestamp.Subtract(start) > TimeSpan.Zero, "Timer may not have fired."); Assert.True(DateTime.Now.Subtract(state.Timestamp) > TimeSpan.FromSeconds(1), $"Timer fired too recently. {DateTime.Now} - {state.Timestamp}"); } -} \ No newline at end of file +} diff --git a/test/Dapr.E2E.Test/Actors/E2ETests.WeaklyTypedTests.cs b/test/Dapr.E2E.Test/Actors/E2ETests.WeaklyTypedTests.cs index c5cc12236..edb964834 100644 --- a/test/Dapr.E2E.Test/Actors/E2ETests.WeaklyTypedTests.cs +++ b/test/Dapr.E2E.Test/Actors/E2ETests.WeaklyTypedTests.cs @@ -20,18 +20,17 @@ namespace Dapr.E2E.Test; using Shouldly; using Xunit; -public partial class E2ETests : IAsyncLifetime +public partial class E2ETests { [Fact] public async Task WeaklyTypedActorCanReturnPolymorphicResponse() { - using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); var pingProxy = this.ProxyFactory.CreateActorProxy(ActorId.CreateRandom(), "WeaklyTypedTestingActor"); var proxy = this.ProxyFactory.Create(ActorId.CreateRandom(), "WeaklyTypedTestingActor"); - await WaitForActorRuntimeAsync(pingProxy, cts.Token); + await WaitForActorRuntimeAsync(pingProxy, TestContext.Current.CancellationToken); - var result = await proxy.InvokeMethodAsync(nameof(IWeaklyTypedTestingActor.GetPolymorphicResponse)); + var result = await proxy.InvokeMethodAsync(nameof(IWeaklyTypedTestingActor.GetPolymorphicResponse), TestContext.Current.CancellationToken); result.ShouldBeOfType().DerivedProperty.ShouldNotBeNullOrWhiteSpace(); } @@ -39,13 +38,12 @@ public async Task WeaklyTypedActorCanReturnPolymorphicResponse() [Fact] public async Task WeaklyTypedActorCanReturnNullResponse() { - using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); var pingProxy = this.ProxyFactory.CreateActorProxy(ActorId.CreateRandom(), "WeaklyTypedTestingActor"); var proxy = this.ProxyFactory.Create(ActorId.CreateRandom(), "WeaklyTypedTestingActor"); - await WaitForActorRuntimeAsync(pingProxy, cts.Token); + await WaitForActorRuntimeAsync(pingProxy, TestContext.Current.CancellationToken); - var result = await proxy.InvokeMethodAsync(nameof(IWeaklyTypedTestingActor.GetNullResponse)); + var result = await proxy.InvokeMethodAsync(nameof(IWeaklyTypedTestingActor.GetNullResponse), TestContext.Current.CancellationToken); result.ShouldBeNull(); } diff --git a/test/Dapr.E2E.Test/Dapr.E2E.Test.csproj b/test/Dapr.E2E.Test/Dapr.E2E.Test.csproj index 93b21ee7d..ccb8be978 100644 --- a/test/Dapr.E2E.Test/Dapr.E2E.Test.csproj +++ b/test/Dapr.E2E.Test/Dapr.E2E.Test.csproj @@ -1,11 +1,14 @@  + + Library + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.E2E.Test/DaprCommand.cs b/test/Dapr.E2E.Test/DaprCommand.cs index c52b64c84..303f77b08 100644 --- a/test/Dapr.E2E.Test/DaprCommand.cs +++ b/test/Dapr.E2E.Test/DaprCommand.cs @@ -11,6 +11,8 @@ // limitations under the License. // ------------------------------------------------------------------------ +using Xunit; + namespace Dapr.E2E.Test; using System; @@ -18,7 +20,6 @@ namespace Dapr.E2E.Test; using System.Diagnostics; using System.Linq; using System.Threading; -using Xunit.Abstractions; public class DaprCommand { diff --git a/test/Dapr.E2E.Test/DaprTestApp.cs b/test/Dapr.E2E.Test/DaprTestApp.cs index 207ae70b4..90f88f46b 100644 --- a/test/Dapr.E2E.Test/DaprTestApp.cs +++ b/test/Dapr.E2E.Test/DaprTestApp.cs @@ -19,7 +19,7 @@ using System.Net.Sockets; using System.Reflection; using System.Runtime.Versioning; -using Xunit.Abstractions; +using Xunit; using static System.IO.Path; namespace Dapr.E2E.Test; diff --git a/test/Dapr.E2E.Test/DaprTestAppFixture.cs b/test/Dapr.E2E.Test/DaprTestAppFixture.cs index b6d199ef1..9fc58ddca 100644 --- a/test/Dapr.E2E.Test/DaprTestAppFixture.cs +++ b/test/Dapr.E2E.Test/DaprTestAppFixture.cs @@ -12,7 +12,7 @@ // ------------------------------------------------------------------------ using System; using System.Threading.Tasks; -using Xunit.Abstractions; +using Xunit; namespace Dapr.E2E.Test; diff --git a/test/Dapr.E2E.Test/DaprTestAppLifecycle.cs b/test/Dapr.E2E.Test/DaprTestAppLifecycle.cs index 1072a54e2..d37d1d2f8 100644 --- a/test/Dapr.E2E.Test/DaprTestAppLifecycle.cs +++ b/test/Dapr.E2E.Test/DaprTestAppLifecycle.cs @@ -16,7 +16,6 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -using Xunit.Abstractions; namespace Dapr.E2E.Test; @@ -43,7 +42,7 @@ public DaprTestAppLifecycle(ITestOutputHelper output, DaprTestAppFixture fixture public ITestOutputHelper Output => this.output; - public async Task InitializeAsync() + public async ValueTask InitializeAsync() { this.state = await this.fixture.StartAsync(this.output, this.Configuration); @@ -66,8 +65,8 @@ public async Task InitializeAsync() throw new TimeoutException("Timed out waiting for daprd health check"); } - public Task DisposeAsync() + public ValueTask DisposeAsync() { - return Task.CompletedTask; + return ValueTask.CompletedTask; } } diff --git a/test/Dapr.E2E.Test/E2ETests.cs b/test/Dapr.E2E.Test/E2ETests.cs index 2e9b5bded..b31c09bf5 100644 --- a/test/Dapr.E2E.Test/E2ETests.cs +++ b/test/Dapr.E2E.Test/E2ETests.cs @@ -18,7 +18,6 @@ using Dapr.Actors.Client; using Dapr.E2E.Test.Actors; using Xunit; -using Xunit.Abstractions; [assembly: CollectionBehavior(DisableTestParallelization = true)] @@ -63,7 +62,7 @@ public E2ETests(ITestOutputHelper output, DaprTestAppFixture fixture) public IActorProxyFactory ProxyFactory => this.HttpEndpoint == null ? null : this.proxyFactory.Value; - public async Task InitializeAsync() + public async ValueTask InitializeAsync() { this.state = await this.fixture.StartAsync(this.Output, this.Configuration); @@ -86,9 +85,9 @@ public async Task InitializeAsync() throw new TimeoutException("Timed out waiting for daprd health check"); } - public Task DisposeAsync() + public ValueTask DisposeAsync() { - return Task.CompletedTask; + return ValueTask.CompletedTask; } protected async Task WaitForActorRuntimeAsync(IPingActor proxy, CancellationToken cancellationToken) diff --git a/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.GrpcProxyInvocationTests.cs b/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.GrpcProxyInvocationTests.cs index de77f7395..c512f0c97 100644 --- a/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.GrpcProxyInvocationTests.cs +++ b/test/Dapr.E2E.Test/ServiceInvocation/E2ETests.GrpcProxyInvocationTests.cs @@ -18,7 +18,6 @@ using Google.Protobuf.WellKnownTypes; using Grpc.Core; using Xunit; -using Xunit.Abstractions; namespace Dapr.E2E.Test; @@ -67,11 +66,11 @@ public async Task TestGrpcProxyStreamingBroadcast() { Assert.Equal($"Hello: {messageReceived++}", response.Message); } - }); + }, TestContext.Current.CancellationToken); for (var i = 0; i < messageCount; i++) { - await call.RequestStream.WriteAsync(new Broadcast { Message = $"Hello: {i}" }); + await call.RequestStream.WriteAsync(new Broadcast { Message = $"Hello: {i}" }, TestContext.Current.CancellationToken); } await call.RequestStream.CompleteAsync(); @@ -94,4 +93,4 @@ public async Task TestGrpcServiceInvocationWithTimeout() Assert.Equal(StatusCode.DeadlineExceeded, ex.StatusCode); } -} \ No newline at end of file +} diff --git a/test/Dapr.Extensions.Configuration.Test/Dapr.Extensions.Configuration.Test.csproj b/test/Dapr.Extensions.Configuration.Test/Dapr.Extensions.Configuration.Test.csproj index 3900bd7e3..1ee4873da 100644 --- a/test/Dapr.Extensions.Configuration.Test/Dapr.Extensions.Configuration.Test.csproj +++ b/test/Dapr.Extensions.Configuration.Test/Dapr.Extensions.Configuration.Test.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Extensions.Configuration.Test/DaprConfigurationStoreProviderTest.cs b/test/Dapr.Extensions.Configuration.Test/DaprConfigurationStoreProviderTest.cs index a1cb299f7..3042323e6 100644 --- a/test/Dapr.Extensions.Configuration.Test/DaprConfigurationStoreProviderTest.cs +++ b/test/Dapr.Extensions.Configuration.Test/DaprConfigurationStoreProviderTest.cs @@ -134,7 +134,7 @@ public async Task TestConfigurationStoreExtension_ProperlyStoresValues() .AddDaprConfigurationStore("store", new List(), daprClient, TimeSpan.FromSeconds(5)) .Build(); - await Task.Delay(TimeSpan.FromMilliseconds(500)); + await Task.Delay(TimeSpan.FromMilliseconds(500), TestContext.Current.CancellationToken); Assert.Equal(item.Value, config["testKey"]); } @@ -165,7 +165,7 @@ public async Task TestStreamingConfigurationStoreExtension_ProperlyStoresValues( .AddStreamingDaprConfigurationStore("store", new List(), daprClient, TimeSpan.FromSeconds(5)) .Build(); - await Task.Delay(TimeSpan.FromMilliseconds(500)); + await Task.Delay(TimeSpan.FromMilliseconds(500), TestContext.Current.CancellationToken); Assert.Equal(item.Value, config["testKey"]); } @@ -204,4 +204,4 @@ private async Task SendStreamingResponseWithConfiguration(Dictionaryruntime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/Dapr.IntegrationTest.DistributedLock/Dapr.IntegrationTest.DistributedLock.csproj b/test/Dapr.IntegrationTest.DistributedLock/Dapr.IntegrationTest.DistributedLock.csproj index cf4e93886..3f1f91ade 100644 --- a/test/Dapr.IntegrationTest.DistributedLock/Dapr.IntegrationTest.DistributedLock.csproj +++ b/test/Dapr.IntegrationTest.DistributedLock/Dapr.IntegrationTest.DistributedLock.csproj @@ -12,8 +12,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/Dapr.IntegrationTest.DistributedLock/DistributedLockTests.cs b/test/Dapr.IntegrationTest.DistributedLock/DistributedLockTests.cs index b64ece2e9..abc502bbd 100644 --- a/test/Dapr.IntegrationTest.DistributedLock/DistributedLockTests.cs +++ b/test/Dapr.IntegrationTest.DistributedLock/DistributedLockTests.cs @@ -17,8 +17,8 @@ public async Task ShouldAcquireAndReleaseLock() var resourceId = $"resource-{Guid.NewGuid():N}"; var owner = $"owner-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir).BuildDistributedLock(); await using var testApp = await DaprHarnessBuilder.ForHarness(harness) @@ -40,10 +40,10 @@ public async Task ShouldAcquireAndReleaseLock() using var scope = testApp.CreateScope(); var client = scope.ServiceProvider.GetRequiredService(); - var acquired = await client.TryLockAsync(componentName, resourceId, owner, expiryInSeconds: 10); + var acquired = await client.TryLockAsync(componentName, resourceId, owner, expiryInSeconds: 10, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(acquired); - var unlock = await client.TryUnlockAsync(componentName, resourceId, owner); + var unlock = await client.TryUnlockAsync(componentName, resourceId, owner, TestContext.Current.CancellationToken); Assert.Equal(LockStatus.Success, unlock.Status); } @@ -55,8 +55,8 @@ public async Task ShouldEnforceExclusivityAndReturnExpectedUnlockStatuses() var owner1 = $"owner-{Guid.NewGuid():N}"; var owner2 = $"owner-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir).BuildDistributedLock(); await using var testApp = await DaprHarnessBuilder.ForHarness(harness) @@ -78,23 +78,23 @@ public async Task ShouldEnforceExclusivityAndReturnExpectedUnlockStatuses() using var scope = testApp.CreateScope(); var client = scope.ServiceProvider.GetRequiredService(); - var lock1 = await client.TryLockAsync(componentName, resourceId, owner1, expiryInSeconds: 20); + var lock1 = await client.TryLockAsync(componentName, resourceId, owner1, expiryInSeconds: 20, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(lock1); // While owner1 holds the lock, owner2 should not be able to acquire it. - var lock2 = await client.TryLockAsync(componentName, resourceId, owner2, expiryInSeconds: 20); + var lock2 = await client.TryLockAsync(componentName, resourceId, owner2, expiryInSeconds: 20, cancellationToken: TestContext.Current.CancellationToken); Assert.Null(lock2); // Wrong owner tries to unlock -> should indicate ownership mismatch. - var wrongUnlock = await client.TryUnlockAsync(componentName, resourceId, owner2); + var wrongUnlock = await client.TryUnlockAsync(componentName, resourceId, owner2, TestContext.Current.CancellationToken); Assert.Equal(LockStatus.LockBelongsToOthers, wrongUnlock.Status); // Correct owner unlocks -> success. - var correctUnlock = await client.TryUnlockAsync(componentName, resourceId, owner1); + var correctUnlock = await client.TryUnlockAsync(componentName, resourceId, owner1, TestContext.Current.CancellationToken); Assert.Equal(LockStatus.Success, correctUnlock.Status); // Unlocking again after release -> lock does not exist. - var secondUnlock = await client.TryUnlockAsync(componentName, resourceId, owner1); + var secondUnlock = await client.TryUnlockAsync(componentName, resourceId, owner1, TestContext.Current.CancellationToken); Assert.Equal(LockStatus.LockDoesNotExist, secondUnlock.Status); } @@ -106,8 +106,8 @@ public async Task ShouldAllowAcquireAfterExpiry() var owner1 = $"owner-{Guid.NewGuid():N}"; var owner2 = $"owner-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir).BuildDistributedLock(); await using var testApp = await DaprHarnessBuilder.ForHarness(harness) @@ -130,7 +130,7 @@ public async Task ShouldAllowAcquireAfterExpiry() var client = scope.ServiceProvider.GetRequiredService(); // Acquire a short-lived lock and *do not* unlock it. - var first = await client.TryLockAsync(componentName, resourceId, owner1, expiryInSeconds: 2); + var first = await client.TryLockAsync(componentName, resourceId, owner1, expiryInSeconds: 2, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(first); // Poll until the lock becomes available and owner2 can acquire it. @@ -142,7 +142,7 @@ public async Task ShouldAllowAcquireAfterExpiry() Assert.NotNull(acquiredByOwner2); - var unlock2 = await client.TryUnlockAsync(componentName, resourceId, owner2); + var unlock2 = await client.TryUnlockAsync(componentName, resourceId, owner2, TestContext.Current.CancellationToken); Assert.Equal(LockStatus.Success, unlock2.Status); } diff --git a/test/Dapr.IntegrationTest.Jobs/Dapr.IntegrationTest.Jobs.csproj b/test/Dapr.IntegrationTest.Jobs/Dapr.IntegrationTest.Jobs.csproj index 2a42de9ea..81c0c1557 100644 --- a/test/Dapr.IntegrationTest.Jobs/Dapr.IntegrationTest.Jobs.csproj +++ b/test/Dapr.IntegrationTest.Jobs/Dapr.IntegrationTest.Jobs.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/test/Dapr.IntegrationTest.Jobs/JobFailurePolicyTests.cs b/test/Dapr.IntegrationTest.Jobs/JobFailurePolicyTests.cs index 80da40be1..aa73f7f05 100644 --- a/test/Dapr.IntegrationTest.Jobs/JobFailurePolicyTests.cs +++ b/test/Dapr.IntegrationTest.Jobs/JobFailurePolicyTests.cs @@ -33,8 +33,8 @@ public async Task ShouldScheduleJobWithDropFailurePolicy() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -70,13 +70,12 @@ public async Task ShouldScheduleJobWithDropFailurePolicy() var dropPolicy = new JobFailurePolicyDropOptions(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), - failurePolicyOptions: dropPolicy, repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), failurePolicyOptions: dropPolicy, repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(jobName, received); - var ex = await Assert.ThrowsAnyAsync(() => daprJobsClient.GetJobAsync(jobName)); + var ex = await Assert.ThrowsAnyAsync(() => daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken)); Assert.NotNull(ex.InnerException); Assert.Contains("job not found", ex.InnerException.Message); } @@ -89,8 +88,8 @@ public async Task ShouldScheduleJobWithConstantFailurePolicy() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -130,13 +129,12 @@ public async Task ShouldScheduleJobWithConstantFailurePolicy() MaxRetries = maxRetries }; - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), - failurePolicyOptions: constantPolicy, repeats: 10, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), failurePolicyOptions: constantPolicy, repeats: 10, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(jobName, received); - var jobDetails = await daprJobsClient.GetJobAsync(jobName); + var jobDetails = await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken); Assert.NotNull(jobDetails.FailurePolicy); Assert.Equal(JobFailurePolicy.Constant, jobDetails.FailurePolicy.Type); if (jobDetails.FailurePolicy is ConfiguredConstantFailurePolicy failurePolicy) diff --git a/test/Dapr.IntegrationTest.Jobs/JobManagementTests.cs b/test/Dapr.IntegrationTest.Jobs/JobManagementTests.cs index 6b1a07fef..2aee5299b 100644 --- a/test/Dapr.IntegrationTest.Jobs/JobManagementTests.cs +++ b/test/Dapr.IntegrationTest.Jobs/JobManagementTests.cs @@ -30,8 +30,8 @@ public async Task ShouldGetJobDetails() var componentsDir = TestDirectoryManager.CreateTestDirectory("jobs-component"); var jobName = $"get-job-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -59,11 +59,10 @@ public async Task ShouldGetJobDetails() var payload = "Test Payload"u8.ToArray(); var schedule = DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(10)); var startingFrom = DateTimeOffset.UtcNow.AddMinutes(1); - await daprJobsClient.ScheduleJobAsync(jobName, schedule, payload, startingFrom: startingFrom, - repeats: 10, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, schedule, payload, startingFrom: startingFrom, repeats: 10, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); var expected = startingFrom.ToLocalTime(); - var jobDetails = await daprJobsClient.GetJobAsync(jobName); + var jobDetails = await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken); Assert.NotNull(jobDetails); Assert.Equal(expected.ToString("O"), jobDetails.Schedule.ExpressionValue); @@ -78,8 +77,8 @@ public async Task ShouldDeleteJob() var componentsDir = TestDirectoryManager.CreateTestDirectory("jobs-component"); var jobName = $"delete-job-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -104,16 +103,15 @@ public async Task ShouldDeleteJob() using var scope = testApp.CreateScope(); var daprJobsClient = scope.ServiceProvider.GetRequiredService(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromHours(1)), - overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromHours(1)), overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var jobDetails = await daprJobsClient.GetJobAsync(jobName); + var jobDetails = await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken); Assert.NotNull(jobDetails); - await daprJobsClient.DeleteJobAsync(jobName); + await daprJobsClient.DeleteJobAsync(jobName, TestContext.Current.CancellationToken); await Assert.ThrowsAsync(async () => - await daprJobsClient.GetJobAsync(jobName)); + await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken)); } [Fact] @@ -122,8 +120,8 @@ public async Task ShouldOverwriteExistingJob() var componentsDir = TestDirectoryManager.CreateTestDirectory("jobs-component"); var jobName = $"overwrite-job-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -149,21 +147,19 @@ public async Task ShouldOverwriteExistingJob() var daprJobsClient = scope.ServiceProvider.GetRequiredService(); var originalPayload = "Original"u8.ToArray(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromHours(1)), - originalPayload, repeats: 5, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromHours(1)), originalPayload, repeats: 5, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var originalDetails = await daprJobsClient.GetJobAsync(jobName); + var originalDetails = await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken); Assert.Equal(5, originalDetails.RepeatCount); var newPayload = "Updated"u8.ToArray(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromMinutes(30)), - newPayload, repeats: 10, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromMinutes(30)), newPayload, repeats: 10, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var updatedDetails = await daprJobsClient.GetJobAsync(jobName); + var updatedDetails = await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken); Assert.Equal(10, updatedDetails.RepeatCount); Assert.Equal(Encoding.UTF8.GetString(newPayload), Encoding.UTF8.GetString(updatedDetails.Payload!)); - await daprJobsClient.DeleteJobAsync(jobName); + await daprJobsClient.DeleteJobAsync(jobName, TestContext.Current.CancellationToken); } [Fact] @@ -172,8 +168,8 @@ public async Task ShouldScheduleJobWithTTL() var componentsDir = TestDirectoryManager.CreateTestDirectory("jobs-component"); var jobName = $"ttl-job-{Guid.NewGuid():N}"; - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -201,13 +197,12 @@ public async Task ShouldScheduleJobWithTTL() var startTime = DateTimeOffset.UtcNow.AddSeconds(2); var ttl = DateTimeOffset.UtcNow.AddMinutes(5); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(1)), - startingFrom: startTime, ttl: ttl, repeats: 100, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(1)), startingFrom: startTime, ttl: ttl, repeats: 100, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var jobDetails = await daprJobsClient.GetJobAsync(jobName); + var jobDetails = await daprJobsClient.GetJobAsync(jobName, TestContext.Current.CancellationToken); Assert.NotNull(jobDetails); Assert.NotNull(jobDetails.Ttl); - await daprJobsClient.DeleteJobAsync(jobName); + await daprJobsClient.DeleteJobAsync(jobName, TestContext.Current.CancellationToken); } } diff --git a/test/Dapr.IntegrationTest.Jobs/JobPayloadTests.cs b/test/Dapr.IntegrationTest.Jobs/JobPayloadTests.cs index 25644d4fe..9c79df291 100644 --- a/test/Dapr.IntegrationTest.Jobs/JobPayloadTests.cs +++ b/test/Dapr.IntegrationTest.Jobs/JobPayloadTests.cs @@ -34,8 +34,8 @@ public async Task ShouldHandleEmptyPayload() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -69,10 +69,9 @@ public async Task ShouldHandleEmptyPayload() using var scope = testApp.CreateScope(); var daprJobsClient = scope.ServiceProvider.GetRequiredService(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), - payload: null, repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), payload: null, repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var isEmpty = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var isEmpty = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.True(isEmpty); } @@ -84,8 +83,8 @@ public async Task ShouldHandleJsonPayload() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -124,10 +123,9 @@ public async Task ShouldHandleJsonPayload() var testPayload = new TestPayload("Test Message", 42, DateTimeOffset.UtcNow); var jsonPayload = JsonSerializer.SerializeToUtf8Bytes(testPayload); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), - jsonPayload, repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), jsonPayload, repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(testPayload.Message, received.Message); Assert.Equal(testPayload.Value, received.Value); } @@ -195,8 +193,8 @@ public async Task ShouldHandleBinaryPayload() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -232,10 +230,9 @@ public async Task ShouldHandleBinaryPayload() var binaryPayload = new byte[] { 0x00, 0xFF, 0x42, 0xAB, 0xCD, 0xEF }; - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), - binaryPayload, repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), binaryPayload, repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(binaryPayload, received); } diff --git a/test/Dapr.IntegrationTest.Jobs/JobSchedulingTests.cs b/test/Dapr.IntegrationTest.Jobs/JobSchedulingTests.cs index a4ddfc9e3..c518e6038 100644 --- a/test/Dapr.IntegrationTest.Jobs/JobSchedulingTests.cs +++ b/test/Dapr.IntegrationTest.Jobs/JobSchedulingTests.cs @@ -32,8 +32,8 @@ public async Task ShouldScheduleJobWithCronExpression() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -70,10 +70,9 @@ public async Task ShouldScheduleJobWithCronExpression() var cronSchedule = new CronExpressionBuilder() .Every(EveryCronPeriod.Second, 15); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromCronExpression(cronSchedule), - repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromCronExpression(cronSchedule), repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(jobName, received); } @@ -85,8 +84,8 @@ public async Task ShouldScheduleJobWithDateTime() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -121,10 +120,9 @@ public async Task ShouldScheduleJobWithDateTime() var daprJobsClient = scope.ServiceProvider.GetRequiredService(); var scheduledTime = DateTimeOffset.UtcNow.AddSeconds(5); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDateTime(scheduledTime), - overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDateTime(scheduledTime), overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(jobName, received); } @@ -136,8 +134,8 @@ public async Task ShouldScheduleJobWithStartingFrom() var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -172,10 +170,9 @@ public async Task ShouldScheduleJobWithStartingFrom() var daprJobsClient = scope.ServiceProvider.GetRequiredService(); var startTime = DateTimeOffset.UtcNow.AddSeconds(5); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(1)), - startingFrom: startTime, repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(1)), startingFrom: startTime, repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(jobName, received); } @@ -188,8 +185,8 @@ public async Task ShouldScheduleMultipleRepeatingJob() var receivedCount = 0; var invocationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -227,10 +224,9 @@ public async Task ShouldScheduleMultipleRepeatingJob() using var scope = testApp.CreateScope(); var daprJobsClient = scope.ServiceProvider.GetRequiredService(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(5)), - repeats: 3, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(5)), repeats: 3, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var finalCount = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var finalCount = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(3, finalCount); } } diff --git a/test/Dapr.IntegrationTest.Jobs/JobsTests.cs b/test/Dapr.IntegrationTest.Jobs/JobsTests.cs index 645ad6f51..7952c0d73 100644 --- a/test/Dapr.IntegrationTest.Jobs/JobsTests.cs +++ b/test/Dapr.IntegrationTest.Jobs/JobsTests.cs @@ -35,8 +35,8 @@ public async Task ShouldScheduleAndReceiveJob() new TaskCompletionSource<(string payload, string jobName)>(TaskCreationOptions .RunContinuationsAsynchronously); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -73,10 +73,9 @@ public async Task ShouldScheduleAndReceiveJob() var daprJobsClient = scope.ServiceProvider.GetRequiredService(); var payload = "Hello!"u8.ToArray(); - await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), - payload, repeats: 1, overwrite: true); + await daprJobsClient.ScheduleJobAsync(jobName, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)), payload, repeats: 1, overwrite: true, cancellationToken: TestContext.Current.CancellationToken); - var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30)); + var received = await invocationTcs.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); Assert.Equal(Encoding.UTF8.GetString(payload), received.payload); Assert.Equal(jobName, received.jobName); } diff --git a/test/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows.csproj b/test/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows.csproj index be5c325db..45cc981fd 100644 --- a/test/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows.csproj +++ b/test/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows/Dapr.IntegrationTest.Workflow.Versioning.ReferenceWorkflows.csproj @@ -4,6 +4,7 @@ enable enable false + Library diff --git a/test/Dapr.IntegrationTest.Workflow.Versioning/CombinedVersioningIntegrationTests.cs b/test/Dapr.IntegrationTest.Workflow.Versioning/CombinedVersioningIntegrationTests.cs index f19b08006..fcdae72a3 100644 --- a/test/Dapr.IntegrationTest.Workflow.Versioning/CombinedVersioningIntegrationTests.cs +++ b/test/Dapr.IntegrationTest.Workflow.Versioning/CombinedVersioningIntegrationTests.cs @@ -39,8 +39,8 @@ public async Task ShouldCombinePatchAndNameBasedVersioning() var componentsDirV1 = TestDirectoryManager.CreateTestDirectory("workflow-versioning-combined-v1"); var componentsDirV2 = TestDirectoryManager.CreateTestDirectory("workflow-versioning-combined-v2"); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); await using (var appV1 = await StartVersionedAppAsync(componentsDirV1, _ => new MinVersionSelector(), environment, options)) @@ -60,7 +60,7 @@ public async Task ShouldCombinePatchAndNameBasedVersioning() } catch (OperationCanceledException) { - var state = await client1.GetWorkflowStateAsync(instanceIdV1, getInputsAndOutputs: false); + var state = await client1.GetWorkflowStateAsync(instanceIdV1, getInputsAndOutputs: false, cancellation: startCts.Token); Assert.Fail($"Timed out waiting for workflow start. Current status: {state?.RuntimeStatus}."); } } @@ -75,14 +75,14 @@ public async Task ShouldCombinePatchAndNameBasedVersioning() var latestNameV2 = GetLatestWorkflowName(scope2.ServiceProvider); Assert.Equal(nameof(CombinedWorkflowV2), latestNameV2); - await client2.RaiseEventAsync(instanceIdV1, ResumeEventName, "resume"); + await client2.RaiseEventAsync(instanceIdV1, ResumeEventName, "resume", TestContext.Current.CancellationToken); using var resumeCts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); var resumed = await client2.WaitForWorkflowCompletionAsync(instanceIdV1, cancellation: resumeCts.Token); Assert.Equal(WorkflowRuntimeStatus.Completed, resumed.RuntimeStatus); Assert.Equal("v1:6:resume", resumed.ReadOutputAs()); await client2.ScheduleNewWorkflowAsync(latestNameV2, instanceIdV2, 5); - await client2.RaiseEventAsync(instanceIdV2, ResumeEventName, "resume"); + await client2.RaiseEventAsync(instanceIdV2, ResumeEventName, "resume", resumeCts.Token); using var latestCts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); var latest = await client2.WaitForWorkflowCompletionAsync(instanceIdV2, cancellation: latestCts.Token); Assert.Equal(WorkflowRuntimeStatus.Completed, latest.RuntimeStatus); diff --git a/test/Dapr.IntegrationTest.Workflow.Versioning/Dapr.IntegrationTest.Workflow.Versioning.csproj b/test/Dapr.IntegrationTest.Workflow.Versioning/Dapr.IntegrationTest.Workflow.Versioning.csproj index f633f8ea4..3d7849761 100644 --- a/test/Dapr.IntegrationTest.Workflow.Versioning/Dapr.IntegrationTest.Workflow.Versioning.csproj +++ b/test/Dapr.IntegrationTest.Workflow.Versioning/Dapr.IntegrationTest.Workflow.Versioning.csproj @@ -17,9 +17,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/test/Dapr.IntegrationTest.Workflow/ActivityCompletionAcknowledgementTests.cs b/test/Dapr.IntegrationTest.Workflow/ActivityCompletionAcknowledgementTests.cs index 9a7abff9d..79275831c 100644 --- a/test/Dapr.IntegrationTest.Workflow/ActivityCompletionAcknowledgementTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ActivityCompletionAcknowledgementTests.cs @@ -28,8 +28,8 @@ public async Task ActivityCompletion_ShouldNotBeRetried_WhenAcknowledged() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir).BuildWorkflow(); await using var testApp = await DaprHarnessBuilder.ForHarness(harness) @@ -57,7 +57,7 @@ public async Task ActivityCompletion_ShouldNotBeRetried_WhenAcknowledged() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(SingleActivityWorkflow), workflowInstanceId, "start"); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true, TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var executionCount = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/ActivityCompletionLoadTests.cs b/test/Dapr.IntegrationTest.Workflow/ActivityCompletionLoadTests.cs index 6a2368523..96b180329 100644 --- a/test/Dapr.IntegrationTest.Workflow/ActivityCompletionLoadTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ActivityCompletionLoadTests.cs @@ -31,8 +31,8 @@ public async Task ActivityCompletions_ShouldBeAcknowledged_UnderLoad() var workflowInstanceId = Guid.NewGuid().ToString(); var loggerProvider = new InMemoryLoggerProvider(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir).BuildWorkflow(); await using var testApp = await DaprHarnessBuilder.ForHarness(harness) @@ -61,7 +61,7 @@ public async Task ActivityCompletions_ShouldBeAcknowledged_UnderLoad() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(FanOutWorkflow), workflowInstanceId, activityCount); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true, TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var completedCount = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/ActivitySleepTests.cs b/test/Dapr.IntegrationTest.Workflow/ActivitySleepTests.cs index 26b5d228c..4edbcff55 100644 --- a/test/Dapr.IntegrationTest.Workflow/ActivitySleepTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ActivitySleepTests.cs @@ -11,6 +11,7 @@ // limitations under the License. // ------------------------------------------------------------------------ +using System.Diagnostics; using Dapr.Testcontainers.Common; using Dapr.Testcontainers.Harnesses; using Dapr.Workflow; @@ -29,8 +30,9 @@ public async Task ShouldHandleActivitySleep() var workflowInstanceId2 = Guid.NewGuid().ToString(); // Build the environment - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + Debug.Assert(environment != null, nameof(environment) + " != null"); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -67,7 +69,7 @@ public async Task ShouldHandleActivitySleep() var cts1 = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(Test2Workflow), workflowInstanceId2, startingValue, null, cts1.Token); - var state = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId1); + var state = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId1, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(state); Assert.Equal(WorkflowRuntimeStatus.Running, state.RuntimeStatus); diff --git a/test/Dapr.IntegrationTest.Workflow/ContinueAsNewTests.cs b/test/Dapr.IntegrationTest.Workflow/ContinueAsNewTests.cs index 4b66d8384..2b3946f3e 100644 --- a/test/Dapr.IntegrationTest.Workflow/ContinueAsNewTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ContinueAsNewTests.cs @@ -27,8 +27,8 @@ public async Task ShouldContinueAsNewUntilComplete() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -52,7 +52,7 @@ public async Task ShouldContinueAsNewUntilComplete() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(CounterWorkflow), workflowInstanceId, 0); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var finalCount = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/Dapr.IntegrationTest.Workflow.csproj b/test/Dapr.IntegrationTest.Workflow/Dapr.IntegrationTest.Workflow.csproj index 5eafb613a..1f7ae35eb 100644 --- a/test/Dapr.IntegrationTest.Workflow/Dapr.IntegrationTest.Workflow.csproj +++ b/test/Dapr.IntegrationTest.Workflow/Dapr.IntegrationTest.Workflow.csproj @@ -12,8 +12,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/Dapr.IntegrationTest.Workflow/DaprApiTokenWorkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/DaprApiTokenWorkflowTests.cs index f9d6807c1..22b8d727a 100644 --- a/test/Dapr.IntegrationTest.Workflow/DaprApiTokenWorkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/DaprApiTokenWorkflowTests.cs @@ -39,8 +39,8 @@ public async Task ShouldRunWorkflowWithDaprApiTokenFromEnvVar() var options = new DaprRuntimeOptions().WithDaprApiToken(daprApiToken); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(options, needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(options, needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -71,7 +71,7 @@ public async Task ShouldRunWorkflowWithDaprApiTokenFromEnvVar() const int startingValue = 8; await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TestWorkflow), workflowInstanceId, startingValue); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true, TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var resultValue = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/ErrorHandlingTests.cs b/test/Dapr.IntegrationTest.Workflow/ErrorHandlingTests.cs index 9a3ae99e3..660319899 100644 --- a/test/Dapr.IntegrationTest.Workflow/ErrorHandlingTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ErrorHandlingTests.cs @@ -27,8 +27,8 @@ public async Task ShouldRetryFailedActivityAndSucceed() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -56,7 +56,7 @@ public async Task ShouldRetryFailedActivityAndSucceed() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(RetryWorkflow), workflowInstanceId, 0); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var output = result.ReadOutputAs(); @@ -69,8 +69,8 @@ public async Task ShouldCancelTimerOnExternalEvent() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -95,12 +95,12 @@ public async Task ShouldCancelTimerOnExternalEvent() var startTime = DateTime.UtcNow; await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(CancellableTimerWorkflow), workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); // Cancel the timer by raising an event - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "CancelTimer"); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "CancelTimer", cancellation: TestContext.Current.CancellationToken); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); var duration = DateTime.UtcNow - startTime; Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); diff --git a/test/Dapr.IntegrationTest.Workflow/ExternalInputWorkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/ExternalInputWorkflowTests.cs index 8855c9df0..cd48f8672 100644 --- a/test/Dapr.IntegrationTest.Workflow/ExternalInputWorkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ExternalInputWorkflowTests.cs @@ -13,11 +13,11 @@ using Dapr.Client; using Dapr.Testcontainers.Common; -using Dapr.Testcontainers.Harnesses; using Dapr.Workflow; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using static Dapr.Testcontainers.Harnesses.DaprTestEnvironment; namespace Dapr.IntegrationTest.Workflow; @@ -36,8 +36,8 @@ public async Task ShouldHandleMultipleExternalEvents_Simple() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -64,14 +64,14 @@ public async Task ShouldHandleMultipleExternalEvents_Simple() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(MultiEventWorkflow), workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); // Raise multiple events - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event1", "FirstData"); - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event2", 42); - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event3", true); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event1", "FirstData", TestContext.Current.CancellationToken); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event2", 42, TestContext.Current.CancellationToken); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event3", true, TestContext.Current.CancellationToken); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var output = result.ReadOutputAs(); Assert.Equal("FirstData-42-True", output); @@ -83,8 +83,8 @@ public async Task ShouldHandleStandardWorkflowsWithDependencyInjection() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -134,8 +134,7 @@ public async Task ShouldHandleStandardWorkflowsWithDependencyInjection() var daprClient = scope.ServiceProvider.GetRequiredService(); foreach (var baseInventoryItem in BaseInventory) { - await daprClient.SaveStateAsync(Testcontainers.Constants.DaprComponentNames.StateManagementComponentName, - baseInventoryItem.Name.ToLowerInvariant(), baseInventoryItem); + await daprClient.SaveStateAsync(Testcontainers.Constants.DaprComponentNames.StateManagementComponentName, baseInventoryItem.Name.ToLowerInvariant(), baseInventoryItem, cancellationToken: TestContext.Current.CancellationToken); } var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); @@ -162,7 +161,7 @@ await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(OrderProcessingWorkflow } catch (OperationCanceledException) { - var state = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, getInputsAndOutputs: true); + var state = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, getInputsAndOutputs: true, cancellation: TestContext.Current.CancellationToken); Assert.Fail($"Timed out waiting for workflow completion. Current state: {state?.RuntimeStatus}, CustomStatus: {state?.ReadCustomStatusAs()}"); throw; } @@ -180,8 +179,8 @@ public async Task ShouldHandleExternalEventTimeout() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -210,7 +209,7 @@ public async Task ShouldHandleExternalEventTimeout() await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TimeoutWorkflow), workflowInstanceId); // Don't send event, let it timeout - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var output = result.ReadOutputAs(); @@ -223,8 +222,8 @@ public async Task ShouldHandleExternalEventWithDefaultValue() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -251,9 +250,9 @@ public async Task ShouldHandleExternalEventWithDefaultValue() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(DefaultValueWorkflow), workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var output = result.ReadOutputAs(); @@ -324,8 +323,8 @@ public async Task ShouldHandleMultipleExternalEvents() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -352,14 +351,14 @@ public async Task ShouldHandleMultipleExternalEvents() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(MultiEventWorkflow), workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); // Raise multiple events - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event1", "FirstData"); - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event2", 42); - await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event3", true); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event1", "FirstData", cancellation: TestContext.Current.CancellationToken); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event2", 42, cancellation: TestContext.Current.CancellationToken); + await daprWorkflowClient.RaiseEventAsync(workflowInstanceId, "Event3", true, cancellation: TestContext.Current.CancellationToken); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var output = result.ReadOutputAs(); Assert.Equal("FirstData-42-True", output); diff --git a/test/Dapr.IntegrationTest.Workflow/FanOutFanInTests.cs b/test/Dapr.IntegrationTest.Workflow/FanOutFanInTests.cs index 7f8a6c6ef..dffcc869f 100644 --- a/test/Dapr.IntegrationTest.Workflow/FanOutFanInTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/FanOutFanInTests.cs @@ -29,8 +29,8 @@ public async Task ShouldFanOutAndFanIn() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -58,7 +58,7 @@ public async Task ShouldFanOutAndFanIn() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TestWorkflow), workflowInstanceId, "test input"); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var resultValue = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/MultiAppActivityTests.cs b/test/Dapr.IntegrationTest.Workflow/MultiAppActivityTests.cs index 3ed93035f..5f2e28b00 100644 --- a/test/Dapr.IntegrationTest.Workflow/MultiAppActivityTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/MultiAppActivityTests.cs @@ -39,8 +39,8 @@ public async Task ShouldScheduleActivityOnRemoteAppUsingAppId() var componentsDir2 = TestDirectoryManager.CreateTestDirectory("workflow-multiapp-activity-2"); // Build our shared environment (Network + Control plane) - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); // Build and start the first application (caller) var harness1 = new DaprHarnessBuilder(componentsDir1) diff --git a/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowAndActivityTests.cs b/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowAndActivityTests.cs index 1585919ed..9ea19699f 100644 --- a/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowAndActivityTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowAndActivityTests.cs @@ -38,8 +38,8 @@ public async Task ShouldScheduleChildWorkflowOnRemoteApp_ThatCallsActivityOnAnot var componentsDir2 = TestDirectoryManager.CreateTestDirectory("workflow-multiapp-chain-2"); var componentsDir3 = TestDirectoryManager.CreateTestDirectory("workflow-multiapp-chain-3"); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); // App1: initiator (calls child workflow on App2) var harness1 = new DaprHarnessBuilder(componentsDir1) diff --git a/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowTests.cs index a278f6e35..1a4c2ff08 100644 --- a/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/MultiAppChildWorkflowTests.cs @@ -38,8 +38,8 @@ public async Task ShouldScheduleChildWorkflowOnRemoteAppUsingAppId() var componentsDir2 = TestDirectoryManager.CreateTestDirectory("workflow-multiapp-2"); // Build our shared environment (Network + Control plane) - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); // Build and start the first application var harness1 = new DaprHarnessBuilder(componentsDir1) diff --git a/test/Dapr.IntegrationTest.Workflow/ParallelExecutionTests.cs b/test/Dapr.IntegrationTest.Workflow/ParallelExecutionTests.cs index 56a2ca6e7..806ee0e60 100644 --- a/test/Dapr.IntegrationTest.Workflow/ParallelExecutionTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ParallelExecutionTests.cs @@ -27,8 +27,8 @@ public async Task ShouldExecuteActivitiesInParallel() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -57,7 +57,7 @@ public async Task ShouldExecuteActivitiesInParallel() var startTime = DateTime.UtcNow; await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(ParallelWorkflow), workflowInstanceId); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); var endTime = DateTime.UtcNow; Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); @@ -76,8 +76,8 @@ public async Task ShouldFanOutFanInWithActivities() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -106,7 +106,7 @@ public async Task ShouldFanOutFanInWithActivities() await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(FanOutFanInWorkflow), workflowInstanceId, (int[])[1, 2, 3, 4 ]); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var sum = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/PauseResumeTests.cs b/test/Dapr.IntegrationTest.Workflow/PauseResumeTests.cs index 629c93516..1bc41a7be 100644 --- a/test/Dapr.IntegrationTest.Workflow/PauseResumeTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/PauseResumeTests.cs @@ -27,8 +27,8 @@ public async Task ShouldReportPausedStatusWhenWorkflowIsSuspended() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -52,13 +52,13 @@ public async Task ShouldReportPausedStatusWhenWorkflowIsSuspended() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(WaitingWorkflow), workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); // Pause the workflow - await daprWorkflowClient.SuspendWorkflowAsync(workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await daprWorkflowClient.SuspendWorkflowAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); - var pausedState = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var pausedState = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(pausedState); Assert.Equal(WorkflowRuntimeStatus.Suspended, pausedState.RuntimeStatus); } @@ -69,8 +69,8 @@ public async Task ShouldPauseAndResumeWorkflow() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -94,21 +94,21 @@ public async Task ShouldPauseAndResumeWorkflow() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(WaitingWorkflow), workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); // Pause the workflow - await daprWorkflowClient.SuspendWorkflowAsync(workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await daprWorkflowClient.SuspendWorkflowAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); - var pausedState = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var pausedState = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(pausedState); Assert.Equal(WorkflowRuntimeStatus.Suspended, pausedState.RuntimeStatus); // Resume the workflow - await daprWorkflowClient.ResumeWorkflowAsync(workflowInstanceId); - await Task.Delay(TimeSpan.FromSeconds(2)); + await daprWorkflowClient.ResumeWorkflowAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); + await Task.Delay(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); - var resumedState = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var resumedState = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(resumedState); Assert.Equal(WorkflowRuntimeStatus.Running, resumedState.RuntimeStatus); } diff --git a/test/Dapr.IntegrationTest.Workflow/PlainWorkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/PlainWorkflowTests.cs index 93b4bcaeb..a54504e8c 100644 --- a/test/Dapr.IntegrationTest.Workflow/PlainWorkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/PlainWorkflowTests.cs @@ -16,8 +16,8 @@ public async Task ShouldHandlePlainWorkflow(bool loadResourcesFirst) var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -49,7 +49,7 @@ public async Task ShouldHandlePlainWorkflow(bool loadResourcesFirst) const int startingValue = 0; await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TestWorkflow), workflowInstanceId, startingValue); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true, TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var resultValue = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/PurgeTests.cs b/test/Dapr.IntegrationTest.Workflow/PurgeTests.cs index 8462f7bc4..6cec68057 100644 --- a/test/Dapr.IntegrationTest.Workflow/PurgeTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/PurgeTests.cs @@ -27,8 +27,8 @@ public async Task ShouldPurgeCompletedWorkflowInstance() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -52,18 +52,18 @@ public async Task ShouldPurgeCompletedWorkflowInstance() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(SimpleWorkflow), workflowInstanceId, "test"); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); // Verify workflow state exists before purge - var stateBeforePurge = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var stateBeforePurge = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(stateBeforePurge); // Purge the workflow instance - await daprWorkflowClient.PurgeInstanceAsync(workflowInstanceId); + await daprWorkflowClient.PurgeInstanceAsync(workflowInstanceId, TestContext.Current.CancellationToken); // Verify workflow state no longer exists after purge - var stateAfterPurge = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var stateAfterPurge = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Null(stateAfterPurge); } diff --git a/test/Dapr.IntegrationTest.Workflow/ReplaySafetyTests.cs b/test/Dapr.IntegrationTest.Workflow/ReplaySafetyTests.cs index 52cd7ee93..f5b8f208e 100644 --- a/test/Dapr.IntegrationTest.Workflow/ReplaySafetyTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/ReplaySafetyTests.cs @@ -28,8 +28,8 @@ public async Task ReplaySafeLogger_ShouldNotDuplicateLogsOnReplay() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -57,7 +57,7 @@ public async Task ReplaySafeLogger_ShouldNotDuplicateLogsOnReplay() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(LoggingWorkflow), workflowInstanceId, "test"); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var output = result.ReadOutputAs(); @@ -70,8 +70,8 @@ public async Task Workflow_ShouldUseDeterministicGuidGeneration() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -98,7 +98,7 @@ public async Task Workflow_ShouldUseDeterministicGuidGeneration() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(DeterministicGuidWorkflow), workflowInstanceId); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var guids = result.ReadOutputAs(); @@ -116,8 +116,8 @@ public async Task NewGuid_ShouldRemainStableAcrossReplays() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) diff --git a/test/Dapr.IntegrationTest.Workflow/SimpleWorkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/SimpleWorkflowTests.cs index c1ef5390d..178f2dcfb 100644 --- a/test/Dapr.IntegrationTest.Workflow/SimpleWorkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/SimpleWorkflowTests.cs @@ -29,8 +29,8 @@ public async Task ShouldHandleSimpleWorkflow(bool loadResourcesFirst) var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -63,7 +63,7 @@ public async Task ShouldHandleSimpleWorkflow(bool loadResourcesFirst) const int startingValue = 8; await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TestWorkflow), workflowInstanceId, startingValue); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true, TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var resultValue = result.ReadOutputAs(); diff --git a/test/Dapr.IntegrationTest.Workflow/SubworkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/SubworkflowTests.cs index 69613b4d0..63644579a 100644 --- a/test/Dapr.IntegrationTest.Workflow/SubworkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/SubworkflowTests.cs @@ -27,8 +27,8 @@ public async Task ShouldHandleSubworkflow() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -57,12 +57,12 @@ public async Task ShouldHandleSubworkflow() await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(DemoWorkflow), workflowInstanceId, workflowInstanceId); - var workflowResult = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var workflowResult = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, workflowResult.RuntimeStatus); var workflowResultValue = workflowResult.ReadOutputAs(); Assert.True(workflowResultValue); - var subworkflowResult = await daprWorkflowClient.WaitForWorkflowCompletionAsync($"{workflowInstanceId}-sub"); + var subworkflowResult = await daprWorkflowClient.WaitForWorkflowCompletionAsync($"{workflowInstanceId}-sub", cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, workflowResult.RuntimeStatus); var subworkflowResultValue = subworkflowResult.ReadOutputAs(); Assert.True(subworkflowResultValue); @@ -74,8 +74,8 @@ public async Task ShouldHandleMultipleParallelSubworkflows() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -106,7 +106,7 @@ await daprWorkflowClient.ScheduleNewWorkflowAsync( nameof(ParallelSubworkflowsWorkflow), workflowInstanceId); - var workflowResult = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var workflowResult = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, workflowResult.RuntimeStatus); var results = workflowResult.ReadOutputAs(); Assert.NotNull(results); diff --git a/test/Dapr.IntegrationTest.Workflow/TaskChainingWorkflowTests.cs b/test/Dapr.IntegrationTest.Workflow/TaskChainingWorkflowTests.cs index a2b142441..20c0bc7ad 100644 --- a/test/Dapr.IntegrationTest.Workflow/TaskChainingWorkflowTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/TaskChainingWorkflowTests.cs @@ -29,8 +29,8 @@ public async Task ShouldHandleTaskChaining() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -62,7 +62,7 @@ public async Task ShouldHandleTaskChaining() const int startingValue = 42; await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TestWorkflow), workflowInstanceId, startingValue); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); var resultValue = result.ReadOutputAs() ?? []; diff --git a/test/Dapr.IntegrationTest.Workflow/TaskExecutionKeyTests.cs b/test/Dapr.IntegrationTest.Workflow/TaskExecutionKeyTests.cs index ea58c686f..29362e6f3 100644 --- a/test/Dapr.IntegrationTest.Workflow/TaskExecutionKeyTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/TaskExecutionKeyTests.cs @@ -27,8 +27,8 @@ public async Task ActivityContext_ShouldContainTaskExecutionKey() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -58,7 +58,7 @@ public async Task ActivityContext_ShouldContainTaskExecutionKey() // Start the workflow await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(GetTaskExecutionKeyWorkflow), workflowInstanceId, "start"); - var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true); + var result = await daprWorkflowClient.WaitForWorkflowCompletionAsync(workflowInstanceId, true, TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); diff --git a/test/Dapr.IntegrationTest.Workflow/TimerTests.cs b/test/Dapr.IntegrationTest.Workflow/TimerTests.cs index d4e830143..905392656 100644 --- a/test/Dapr.IntegrationTest.Workflow/TimerTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/TimerTests.cs @@ -30,8 +30,8 @@ public async Task ValidateStatusMessagesWithDelay() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -59,20 +59,20 @@ public async Task ValidateStatusMessagesWithDelay() var daprWorkflowClient = scope.ServiceProvider.GetRequiredService(); await daprWorkflowClient.ScheduleNewWorkflowAsync(nameof(TestWorkflow), workflowInstanceId, 8); - await Task.Delay(TimeSpan.FromSeconds(3)); + await Task.Delay(TimeSpan.FromSeconds(3), TestContext.Current.CancellationToken); // Get the initial status - var initialStatus = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var initialStatus = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(initialStatus); Assert.Equal(WorkflowRuntimeStatus.Running, initialStatus.RuntimeStatus); var initialStatusResult = initialStatus.ReadCustomStatusAs(); Assert.Equal(InitialMessage, initialStatusResult); // Wait 20 seconds - await Task.Delay(TimeSpan.FromSeconds(20)); + await Task.Delay(TimeSpan.FromSeconds(20), TestContext.Current.CancellationToken); // Get the current status - var finalStatus = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId); + var finalStatus = await daprWorkflowClient.GetWorkflowStateAsync(workflowInstanceId, cancellation: TestContext.Current.CancellationToken); Assert.NotNull(finalStatus); var finalStatusResult = finalStatus.ReadCustomStatusAs(); Assert.Equal(FinalMessage, finalStatusResult); diff --git a/test/Dapr.IntegrationTest.Workflow/WorkflowMonitorTests.cs b/test/Dapr.IntegrationTest.Workflow/WorkflowMonitorTests.cs index c03ac0ec1..03fe6d8bb 100644 --- a/test/Dapr.IntegrationTest.Workflow/WorkflowMonitorTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/WorkflowMonitorTests.cs @@ -27,8 +27,8 @@ public async Task ShouldHandleContinueAsNew() var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); var workflowInstanceId = Guid.NewGuid().ToString(); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) diff --git a/test/Dapr.IntegrationTest.Workflow/WorkflowRpcTests.cs b/test/Dapr.IntegrationTest.Workflow/WorkflowRpcTests.cs index 80a5d374f..2eab307b9 100644 --- a/test/Dapr.IntegrationTest.Workflow/WorkflowRpcTests.cs +++ b/test/Dapr.IntegrationTest.Workflow/WorkflowRpcTests.cs @@ -27,8 +27,8 @@ public async Task ListInstanceIds_ShouldReturnScheduledWorkflowInstances() { var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -54,10 +54,10 @@ public async Task ListInstanceIds_ShouldReturnScheduledWorkflowInstances() // Schedule a workflow and wait for completion var instanceId = Guid.NewGuid().ToString(); await client.ScheduleNewWorkflowAsync(nameof(SimpleWorkflow), instanceId, "hello"); - await client.WaitForWorkflowCompletionAsync(instanceId); + await client.WaitForWorkflowCompletionAsync(instanceId, cancellation: TestContext.Current.CancellationToken); // List instance IDs and verify our workflow appears - var page = await client.ListInstanceIdsAsync(); + var page = await client.ListInstanceIdsAsync(cancellation: TestContext.Current.CancellationToken); Assert.NotNull(page); Assert.Contains(instanceId, page.InstanceIds); @@ -68,8 +68,8 @@ public async Task GetInstanceHistory_ShouldReturnHistoryForCompletedWorkflow() { var componentsDir = TestDirectoryManager.CreateTestDirectory("workflow-components"); - await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true); - await environment.StartAsync(); + await using var environment = await DaprTestEnvironment.CreateWithPooledNetworkAsync(needsActorState: true, cancellationToken: TestContext.Current.CancellationToken); + await environment.StartAsync(TestContext.Current.CancellationToken); var harness = new DaprHarnessBuilder(componentsDir) .WithEnvironment(environment) @@ -99,11 +99,11 @@ public async Task GetInstanceHistory_ShouldReturnHistoryForCompletedWorkflow() // Schedule a workflow with an activity and wait for completion var instanceId = Guid.NewGuid().ToString(); await client.ScheduleNewWorkflowAsync(nameof(WorkflowWithActivity), instanceId, "test-input"); - var result = await client.WaitForWorkflowCompletionAsync(instanceId); + var result = await client.WaitForWorkflowCompletionAsync(instanceId, cancellation: TestContext.Current.CancellationToken); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); // Get history and verify it has events - var history = await client.GetInstanceHistoryAsync(instanceId); + var history = await client.GetInstanceHistoryAsync(instanceId, TestContext.Current.CancellationToken); Assert.NotNull(history); Assert.NotEmpty(history); diff --git a/test/Dapr.Jobs.Analyzer.Test/Dapr.Jobs.Analyzers.Test.csproj b/test/Dapr.Jobs.Analyzer.Test/Dapr.Jobs.Analyzers.Test.csproj index bcad911e5..e9ce86571 100644 --- a/test/Dapr.Jobs.Analyzer.Test/Dapr.Jobs.Analyzers.Test.csproj +++ b/test/Dapr.Jobs.Analyzer.Test/Dapr.Jobs.Analyzers.Test.csproj @@ -12,7 +12,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Dapr.Jobs.Test/Dapr.Jobs.Test.csproj b/test/Dapr.Jobs.Test/Dapr.Jobs.Test.csproj index 7e0b63398..191492ec2 100644 --- a/test/Dapr.Jobs.Test/Dapr.Jobs.Test.csproj +++ b/test/Dapr.Jobs.Test/Dapr.Jobs.Test.csproj @@ -11,8 +11,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Jobs.Test/DaprJobsGrpcClientTests.cs b/test/Dapr.Jobs.Test/DaprJobsGrpcClientTests.cs index b0192fb76..0f15693e1 100644 --- a/test/Dapr.Jobs.Test/DaprJobsGrpcClientTests.cs +++ b/test/Dapr.Jobs.Test/DaprJobsGrpcClientTests.cs @@ -33,7 +33,7 @@ public void ScheduleJobAsync_RepeatsCannotBeLessThanZero() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.ScheduleJobAsync("MyJob", DaprJobSchedule.Daily, null, null, -5, null, default); + await client.ScheduleJobAsync("MyJob", DaprJobSchedule.Daily, null, null, -5, null, default, cancellationToken: TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -49,7 +49,7 @@ public void ScheduleJobAsync_JobNameCannotBeNull() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.ScheduleJobAsync(null, DaprJobSchedule.Daily, null, null, -5, null, default); + await client.ScheduleJobAsync(null, DaprJobSchedule.Daily, null, null, -5, null, default, cancellationToken: TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -65,7 +65,7 @@ public void ScheduleJobAsync_JobNameCannotBeEmpty() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.ScheduleJobAsync(string.Empty, DaprJobSchedule.Daily, null, null, -5, null, default); + await client.ScheduleJobAsync(string.Empty, DaprJobSchedule.Daily, null, null, -5, null, default, cancellationToken: TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -81,7 +81,7 @@ public void ScheduleJobAsync_ScheduleCannotBeEmpty() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.ScheduleJobAsync("MyJob", new DaprJobSchedule(string.Empty), null, null, -5, null, default); + await client.ScheduleJobAsync("MyJob", new DaprJobSchedule(string.Empty), null, null, -5, null, default, cancellationToken: TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -99,7 +99,7 @@ public void ScheduleJobAsync_TtlCannotBeEarlierThanStartingFrom() { var date = DateTime.UtcNow.AddDays(10); var earlierDate = date.AddDays(-2); - await client.ScheduleJobAsync("MyJob", DaprJobSchedule.Daily, null, date, null, earlierDate, default); + await client.ScheduleJobAsync("MyJob", DaprJobSchedule.Daily, null, date, null, earlierDate, default, cancellationToken: TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -115,7 +115,7 @@ public void GetJobAsync_NameCannotBeNull() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.GetJobAsync(null, default); + await client.GetJobAsync(null, TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -131,7 +131,7 @@ public void GetJobAsync_NameCannotBeEmpty() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.GetJobAsync(string.Empty, default); + await client.GetJobAsync(string.Empty, TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -147,7 +147,7 @@ public void DeleteJobAsync_NameCannotBeNull() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.DeleteJobAsync(null, default); + await client.DeleteJobAsync(null, TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } @@ -163,7 +163,7 @@ public void DeleteJobAsync_NameCannotBeEmpty() #pragma warning disable CS0618 // Type or member is obsolete var result = Assert.ThrowsAsync(async () => { - await client.DeleteJobAsync(string.Empty, default); + await client.DeleteJobAsync(string.Empty, TestContext.Current.CancellationToken); }); #pragma warning restore CS0618 // Type or member is obsolete } diff --git a/test/Dapr.Jobs.Test/Extensions/EndpointRouteBuilderExtensionsTests.cs b/test/Dapr.Jobs.Test/Extensions/EndpointRouteBuilderExtensionsTests.cs index 3de167db7..9231c3ab6 100644 --- a/test/Dapr.Jobs.Test/Extensions/EndpointRouteBuilderExtensionsTests.cs +++ b/test/Dapr.Jobs.Test/Extensions/EndpointRouteBuilderExtensionsTests.cs @@ -39,7 +39,7 @@ public async Task MapDaprScheduledJobHandler_ValidRequest_ExecutesAction() var content = new StringContent(serializedPayload, Encoding.UTF8, "application/json"); const string jobName = "testJob"; - var response = await client.PostAsync($"/job/{jobName}", content); + var response = await client.PostAsync($"/job/{jobName}", content, TestContext.Current.CancellationToken); response.EnsureSuccessStatusCode(); @@ -59,7 +59,7 @@ public async Task MapDaprScheduleJobHandler_HandleMissingCancellationToken() var content = new StringContent(serializedPayload, Encoding.UTF8, "application/json"); const string jobName = "testJob"; - var response = await client.PostAsync($"/job/{jobName}", content); + var response = await client.PostAsync($"/job/{jobName}", content, TestContext.Current.CancellationToken); response.EnsureSuccessStatusCode(); @@ -101,7 +101,7 @@ await Task.Delay(TimeSpan.FromSeconds(1), return Task.CompletedTask; }, timeout); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var testServer = app.GetTestServer(); var client = testServer.CreateClient(); @@ -112,7 +112,7 @@ await Task.Delay(TimeSpan.FromSeconds(1), }; // Act & Assert - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.True(response.IsSuccessStatusCode); } @@ -131,8 +131,8 @@ public async Task MapDaprScheduledJobHandler_AppliesTimeoutCorrectly() var app = builder.Build(); app.UseRouting(); app.MapDaprScheduledJobHandler(async ( - string jobName, - ReadOnlyMemory jobPayload, + string _, + ReadOnlyMemory _, ILogger? logger, CancellationToken cancellationToken) => { @@ -149,7 +149,7 @@ public async Task MapDaprScheduledJobHandler_AppliesTimeoutCorrectly() return Task.CompletedTask; }, timeout); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var testServer = app.GetTestServer(); var client = testServer.CreateClient(); client.Timeout = TimeSpan.FromSeconds(20); @@ -163,7 +163,7 @@ public async Task MapDaprScheduledJobHandler_AppliesTimeoutCorrectly() // Act & Assert try { - var response = await client.SendAsync(request); + var response = await client.SendAsync(request, TestContext.Current.CancellationToken); Assert.Equal(System.Net.HttpStatusCode.InternalServerError, response.StatusCode); } catch (Exception ex) diff --git a/test/Dapr.Messaging.Test/Dapr.Messaging.Test.csproj b/test/Dapr.Messaging.Test/Dapr.Messaging.Test.csproj index d4ee12bd2..be4e87adb 100644 --- a/test/Dapr.Messaging.Test/Dapr.Messaging.Test.csproj +++ b/test/Dapr.Messaging.Test/Dapr.Messaging.Test.csproj @@ -18,7 +18,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Messaging.Test/PublishSubscribe/PublishSubscribeReceiverTests.cs b/test/Dapr.Messaging.Test/PublishSubscribe/PublishSubscribeReceiverTests.cs index f8070aa66..25924e959 100644 --- a/test/Dapr.Messaging.Test/PublishSubscribe/PublishSubscribeReceiverTests.cs +++ b/test/Dapr.Messaging.Test/PublishSubscribe/PublishSubscribeReceiverTests.cs @@ -53,7 +53,7 @@ public void SubscribeAsync_ShouldNotBlock() var receiver = new PublishSubscribeReceiver(pubSubName, topicName, options, messageHandler, mockDaprClient.Object); var stopwatch = System.Diagnostics.Stopwatch.StartNew(); - var subscribeTask = receiver.SubscribeAsync(); + var subscribeTask = receiver.SubscribeAsync(TestContext.Current.CancellationToken); stopwatch.Stop(); Assert.True(stopwatch.ElapsedMilliseconds < 100, "SubscribeAsync should return immediately and not block"); @@ -109,14 +109,14 @@ public async Task ProcessTopicChannelMessagesAsync_ShouldProcessMessages() .Returns(mockCall); var receiver = new PublishSubscribeReceiver(pubSubName, topicName, options, mockMessageHandler.Object, mockDaprClient.Object); - await receiver.SubscribeAsync(); + await receiver.SubscribeAsync(TestContext.Current.CancellationToken); //Write a message to the channel var message = new TopicMessage("id", "source", "type", "specVersion", "dataContentType", topicName, pubSubName); await receiver.WriteMessageToChannelAsync(message); //Allow some time for the message to be processed - await Task.Delay(100); + await Task.Delay(100, TestContext.Current.CancellationToken); mockMessageHandler.Verify(handler => handler(It.IsAny(), It.IsAny()), Times.Once); @@ -153,7 +153,7 @@ public async Task SubscribeAsync_ShouldProcessAcknowledgements() var receiver = new PublishSubscribeReceiver(pubSubName, topicName, options, mockMessageHandler.Object, mockDaprClient.Object); - await receiver.SubscribeAsync(); + await receiver.SubscribeAsync(TestContext.Current.CancellationToken); // Use reflection to access the private acknowledgementsChannel and write an acknowledgement var acknowledgementsChannelField = typeof(PublishSubscribeReceiver).GetField("acknowledgementsChannel", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); @@ -162,10 +162,10 @@ public async Task SubscribeAsync_ShouldProcessAcknowledgements() var acknowledgementsChannel = (Channel)acknowledgementsChannelField.GetValue(receiver)!; var acknowledgement = new PublishSubscribeReceiver.TopicAcknowledgement("id", TopicEventResponse.Types.TopicEventResponseStatus.Success); - await acknowledgementsChannel.Writer.WriteAsync(acknowledgement); + await acknowledgementsChannel.Writer.WriteAsync(acknowledgement, TestContext.Current.CancellationToken); // Allow some time for the acknowledgement to be processed - await Task.Delay(100); + await Task.Delay(100, TestContext.Current.CancellationToken); // Verify that the request stream's WriteAsync method was called twice (initial request + acknowledgement) mockRequestStream.Verify(stream => stream.WriteAsync(It.IsAny(), It.IsAny()), Times.Exactly(2)); diff --git a/test/Dapr.Testcontainers.Test/Dapr.Testcontainers.Test.csproj b/test/Dapr.Testcontainers.Test/Dapr.Testcontainers.Test.csproj index b6773f533..3b27362c2 100644 --- a/test/Dapr.Testcontainers.Test/Dapr.Testcontainers.Test.csproj +++ b/test/Dapr.Testcontainers.Test/Dapr.Testcontainers.Test.csproj @@ -18,7 +18,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Workflow.Abstractions.Test/Dapr.Workflow.Abstractions.Test.csproj b/test/Dapr.Workflow.Abstractions.Test/Dapr.Workflow.Abstractions.Test.csproj index d44d342a2..94082b11f 100644 --- a/test/Dapr.Workflow.Abstractions.Test/Dapr.Workflow.Abstractions.Test.csproj +++ b/test/Dapr.Workflow.Abstractions.Test/Dapr.Workflow.Abstractions.Test.csproj @@ -12,7 +12,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/test/Dapr.Workflow.Analyzers.Test/Dapr.Workflow.Analyzers.Test.csproj b/test/Dapr.Workflow.Analyzers.Test/Dapr.Workflow.Analyzers.Test.csproj index 83139ac4e..92daa4429 100644 --- a/test/Dapr.Workflow.Analyzers.Test/Dapr.Workflow.Analyzers.Test.csproj +++ b/test/Dapr.Workflow.Analyzers.Test/Dapr.Workflow.Analyzers.Test.csproj @@ -14,8 +14,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/Dapr.Workflow.Test/Client/WorkflowGrpcClientTests.cs b/test/Dapr.Workflow.Test/Client/WorkflowGrpcClientTests.cs index c21f7b0ac..b3a759093 100644 --- a/test/Dapr.Workflow.Test/Client/WorkflowGrpcClientTests.cs +++ b/test/Dapr.Workflow.Test/Client/WorkflowGrpcClientTests.cs @@ -37,10 +37,7 @@ public async Task ScheduleNewWorkflowAsync_ShouldUseProvidedInstanceId_WhenOptio var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var instanceId = await client.ScheduleNewWorkflowAsync( - "MyWorkflow", - input: new { A = 1 }, - options: new StartWorkflowOptions { InstanceId = "instance-123" }); + var instanceId = await client.ScheduleNewWorkflowAsync("MyWorkflow", input: new { A = 1 }, options: new StartWorkflowOptions { InstanceId = "instance-123" }, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("id-from-sidecar", instanceId); Assert.NotNull(capturedRequest); @@ -64,7 +61,7 @@ public async Task ScheduleNewWorkflowAsync_ShouldGenerateNonEmptyInstanceId_When var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.ScheduleNewWorkflowAsync("MyWorkflow", input: null, options: new StartWorkflowOptions { InstanceId = null }); + await client.ScheduleNewWorkflowAsync("MyWorkflow", input: null, options: new StartWorkflowOptions { InstanceId = null }, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(capturedRequest); Assert.False(string.IsNullOrEmpty(capturedRequest!.InstanceId)); @@ -86,10 +83,7 @@ public async Task ScheduleNewWorkflowAsync_ShouldSetScheduledStartTimestamp_When var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.ScheduleNewWorkflowAsync( - "MyWorkflow", - input: null, - options: new StartWorkflowOptions { InstanceId = "i", StartAt = startAt }); + await client.ScheduleNewWorkflowAsync("MyWorkflow", input: null, options: new StartWorkflowOptions { InstanceId = "i", StartAt = startAt }, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(capturedRequest); Assert.NotNull(capturedRequest!.ScheduledStartTimestamp); @@ -108,7 +102,7 @@ public async Task GetWorkflowMetadataAsync_ShouldReturnNull_WhenResponseExistsIs var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.GetWorkflowMetadataAsync("missing", getInputsAndOutputs: true); + var result = await client.GetWorkflowMetadataAsync("missing", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken); Assert.Null(result); } @@ -125,7 +119,7 @@ public async Task GetWorkflowMetadataAsync_ShouldReturnNull_WhenGrpcThrowsNotFou var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.GetWorkflowMetadataAsync("missing", getInputsAndOutputs: true); + var result = await client.GetWorkflowMetadataAsync("missing", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken); Assert.Null(result); } @@ -149,7 +143,7 @@ public async Task GetWorkflowMetadataAsync_ShouldPassThroughGetInputsAndOutputsF var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.GetWorkflowMetadataAsync("i", getInputsAndOutputs: false); + await client.GetWorkflowMetadataAsync("i", getInputsAndOutputs: false, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -177,7 +171,7 @@ public async Task WaitForWorkflowStartAsync_ShouldReturnImmediately_WhenStatusIs var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.WaitForWorkflowStartAsync("i", getInputsAndOutputs: true); + var result = await client.WaitForWorkflowStartAsync("i", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("i", result.InstanceId); Assert.Equal(WorkflowRuntimeStatus.Running, result.RuntimeStatus); @@ -195,7 +189,7 @@ public async Task WaitForWorkflowStartAsync_ShouldThrowInvalidOperationException var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await Assert.ThrowsAsync(() => client.WaitForWorkflowStartAsync("missing", getInputsAndOutputs: true)); + await Assert.ThrowsAsync(() => client.WaitForWorkflowStartAsync("missing", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken)); } [Fact] @@ -220,7 +214,7 @@ public async Task WaitForWorkflowCompletionAsync_ShouldReturnImmediately_WhenSta var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.WaitForWorkflowCompletionAsync("i", getInputsAndOutputs: true); + var result = await client.WaitForWorkflowCompletionAsync("i", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("i", result.InstanceId); Assert.Equal(WorkflowRuntimeStatus.Completed, result.RuntimeStatus); @@ -234,7 +228,7 @@ public async Task RaiseEventAsync_ShouldThrowArgumentException_WhenInstanceIdIsN var grpcClientMock = CreateGrpcClientMock(); var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await Assert.ThrowsAsync(() => client.RaiseEventAsync("", "evt", eventPayload: null)); + await Assert.ThrowsAsync(() => client.RaiseEventAsync("", "evt", eventPayload: null, cancellationToken: TestContext.Current.CancellationToken)); } [Fact] @@ -244,7 +238,7 @@ public async Task RaiseEventAsync_ShouldThrowArgumentException_WhenEventNameIsNu var grpcClientMock = CreateGrpcClientMock(); var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await Assert.ThrowsAsync(() => client.RaiseEventAsync("i", "", eventPayload: null)); + await Assert.ThrowsAsync(() => client.RaiseEventAsync("i", "", eventPayload: null, cancellationToken: TestContext.Current.CancellationToken)); } [Fact] @@ -261,7 +255,7 @@ public async Task RaiseEventAsync_ShouldSendSerializedPayload() var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.RaiseEventAsync("i", "evt", new { P = 1 }); + await client.RaiseEventAsync("i", "evt", new { P = 1 }, TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -283,7 +277,7 @@ public async Task TerminateWorkflowAsync_ShouldSendRecursiveTrue_AndSerializedOu var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.TerminateWorkflowAsync("i", output: new { Done = true }); + await client.TerminateWorkflowAsync("i", output: new { Done = true }, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -305,7 +299,7 @@ public async Task SuspendWorkflowAsync_ShouldSendEmptyReason_WhenReasonIsNull() var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.SuspendWorkflowAsync("i", reason: null); + await client.SuspendWorkflowAsync("i", reason: null, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -326,7 +320,7 @@ public async Task ResumeWorkflowAsync_ShouldSendEmptyReason_WhenReasonIsNull() var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await client.ResumeWorkflowAsync("i", reason: null); + await client.ResumeWorkflowAsync("i", reason: null, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -350,7 +344,7 @@ public async Task PurgeInstanceAsync_ShouldReturnTrueOnlyWhenDeletedInstanceCoun var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.PurgeInstanceAsync("i"); + var result = await client.PurgeInstanceAsync("i", TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -376,7 +370,7 @@ public async Task ListInstanceIdsAsync_ShouldSendRequestAndReturnPage() var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.ListInstanceIdsAsync(continuationToken: "prev-token", pageSize: 3); + var result = await client.ListInstanceIdsAsync(continuationToken: "prev-token", pageSize: 3, cancellationToken: TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("prev-token", captured!.ContinuationToken); @@ -401,7 +395,7 @@ public async Task ListInstanceIdsAsync_ShouldReturnNullContinuationToken_WhenNon var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.ListInstanceIdsAsync(); + var result = await client.ListInstanceIdsAsync(cancellationToken: TestContext.Current.CancellationToken); Assert.Single(result.InstanceIds); Assert.Null(result.ContinuationToken); @@ -414,7 +408,7 @@ public async Task GetInstanceHistoryAsync_ShouldThrowArgumentException_WhenInsta var grpcClientMock = CreateGrpcClientMock(); var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await Assert.ThrowsAsync(() => client.GetInstanceHistoryAsync("")); + await Assert.ThrowsAsync(() => client.GetInstanceHistoryAsync("", TestContext.Current.CancellationToken)); } [Fact] @@ -451,7 +445,7 @@ public async Task GetInstanceHistoryAsync_ShouldReturnConvertedHistoryEvents() var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.GetInstanceHistoryAsync("i"); + var result = await client.GetInstanceHistoryAsync("i", TestContext.Current.CancellationToken); Assert.NotNull(captured); Assert.Equal("i", captured!.InstanceId); @@ -469,7 +463,7 @@ public async Task RerunWorkflowFromEventAsync_ShouldThrowArgumentException_WhenS var grpcClientMock = CreateGrpcClientMock(); var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - await Assert.ThrowsAsync(() => client.RerunWorkflowFromEventAsync("", 1)); + await Assert.ThrowsAsync(() => client.RerunWorkflowFromEventAsync("", 1, cancellationToken: TestContext.Current.CancellationToken)); } [Fact] @@ -493,7 +487,7 @@ public async Task RerunWorkflowFromEventAsync_ShouldSendRequestAndReturnNewInsta OverwriteInput = true }; - var result = await client.RerunWorkflowFromEventAsync("source-id", 42, options); + var result = await client.RerunWorkflowFromEventAsync("source-id", 42, options, TestContext.Current.CancellationToken); Assert.Equal("new-instance", result); Assert.NotNull(captured); @@ -518,7 +512,7 @@ public async Task RerunWorkflowFromEventAsync_ShouldNotSetOptionalFields_WhenOpt var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.RerunWorkflowFromEventAsync("source-id", 5); + var result = await client.RerunWorkflowFromEventAsync("source-id", 5, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("auto-id", result); Assert.NotNull(captured); @@ -655,7 +649,7 @@ public async Task WaitForWorkflowCompletionAsync_ShouldReturnImmediately_WhenSta var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); - var result = await client.WaitForWorkflowCompletionAsync("i", getInputsAndOutputs: true); + var result = await client.WaitForWorkflowCompletionAsync("i", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("i", result.InstanceId); Assert.Equal(expectedStatus, result.RuntimeStatus); @@ -674,7 +668,7 @@ public async Task WaitForWorkflowCompletionAsync_ShouldThrowInvalidOperationExce var client = new WorkflowGrpcClient(grpcClientMock.Object, NullLogger.Instance, serializer); var ex = await Assert.ThrowsAsync( - () => client.WaitForWorkflowCompletionAsync("missing", getInputsAndOutputs: true)); + () => client.WaitForWorkflowCompletionAsync("missing", getInputsAndOutputs: true, cancellationToken: TestContext.Current.CancellationToken)); Assert.Contains("missing", ex.Message); } diff --git a/test/Dapr.Workflow.Test/Dapr.Workflow.Test.csproj b/test/Dapr.Workflow.Test/Dapr.Workflow.Test.csproj index bcb10082d..517260d86 100644 --- a/test/Dapr.Workflow.Test/Dapr.Workflow.Test.csproj +++ b/test/Dapr.Workflow.Test/Dapr.Workflow.Test.csproj @@ -14,8 +14,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/Dapr.Workflow.Test/DaprWorkflowClientTests.cs b/test/Dapr.Workflow.Test/DaprWorkflowClientTests.cs index 0498d3756..7f8264fa7 100644 --- a/test/Dapr.Workflow.Test/DaprWorkflowClientTests.cs +++ b/test/Dapr.Workflow.Test/DaprWorkflowClientTests.cs @@ -80,7 +80,7 @@ public async Task GetWorkflowStateAsync_ShouldThrowArgumentException_WhenInstanc var inner = new CapturingWorkflowClient(); var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.GetWorkflowStateAsync("")); + await Assert.ThrowsAsync(() => client.GetWorkflowStateAsync("", cancellation: TestContext.Current.CancellationToken)); } [Fact] @@ -89,7 +89,7 @@ public async Task GetWorkflowStateAsync_ShouldReturnNull_WhenInnerReturnsNullMet var inner = new CapturingWorkflowClient { GetWorkflowMetadataResult = null }; var client = new DaprWorkflowClient(inner); - var state = await client.GetWorkflowStateAsync("missing"); + var state = await client.GetWorkflowStateAsync("missing", cancellation: TestContext.Current.CancellationToken); Assert.Null(state); Assert.Equal("missing", inner.LastGetMetadataInstanceId); @@ -110,7 +110,7 @@ public async Task GetWorkflowStateAsync_ShouldReturnWorkflowState_WhenInnerRetur var inner = new CapturingWorkflowClient { GetWorkflowMetadataResult = metadata }; var client = new DaprWorkflowClient(inner); - var state = await client.GetWorkflowStateAsync("i"); + var state = await client.GetWorkflowStateAsync("i", cancellation: TestContext.Current.CancellationToken); Assert.NotNull(state); Assert.True(state!.Exists); @@ -124,7 +124,7 @@ public async Task WaitForWorkflowStartAsync_ShouldThrowArgumentException_WhenIns var inner = new CapturingWorkflowClient(); var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.WaitForWorkflowStartAsync("")); + await Assert.ThrowsAsync(() => client.WaitForWorkflowStartAsync("", cancellation: TestContext.Current.CancellationToken)); } [Fact] @@ -141,7 +141,7 @@ public async Task WaitForWorkflowStartAsync_ShouldWrapMetadataIntoWorkflowState( var inner = new CapturingWorkflowClient { WaitForStartResult = metadata }; var client = new DaprWorkflowClient(inner); - var state = await client.WaitForWorkflowStartAsync("i", getInputsAndOutputs: false); + var state = await client.WaitForWorkflowStartAsync("i", getInputsAndOutputs: false, cancellation: TestContext.Current.CancellationToken); Assert.True(state.Exists); Assert.Equal(WorkflowRuntimeStatus.Running, state.RuntimeStatus); @@ -155,7 +155,7 @@ public async Task WaitForWorkflowCompletionAsync_ShouldThrowArgumentException_Wh var inner = new CapturingWorkflowClient(); var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.WaitForWorkflowCompletionAsync("")); + await Assert.ThrowsAsync(() => client.WaitForWorkflowCompletionAsync("", cancellation: TestContext.Current.CancellationToken)); } [Fact] @@ -164,10 +164,10 @@ public async Task RaiseEventAsync_ShouldValidateParameters_AndForwardToInner() var inner = new CapturingWorkflowClient(); var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.RaiseEventAsync("", "evt")); - await Assert.ThrowsAsync(() => client.RaiseEventAsync("i", "")); + await Assert.ThrowsAsync(() => client.RaiseEventAsync("", "evt", cancellation: TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => client.RaiseEventAsync("i", "", cancellation: TestContext.Current.CancellationToken)); - await client.RaiseEventAsync("i", "evt", new { P = 1 }); + await client.RaiseEventAsync("i", "evt", new { P = 1 }, TestContext.Current.CancellationToken); Assert.Equal("i", inner.LastRaiseEventInstanceId); Assert.Equal("evt", inner.LastRaiseEventName); @@ -180,15 +180,15 @@ public async Task TerminateSuspendResumePurge_ShouldValidateInstanceId_AndForwar var inner = new CapturingWorkflowClient { PurgeResult = true }; var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.TerminateWorkflowAsync("")); - await Assert.ThrowsAsync(() => client.SuspendWorkflowAsync("")); - await Assert.ThrowsAsync(() => client.ResumeWorkflowAsync("")); - await Assert.ThrowsAsync(() => client.PurgeInstanceAsync("")); + await Assert.ThrowsAsync(() => client.TerminateWorkflowAsync("", cancellation: TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => client.SuspendWorkflowAsync("", cancellation: TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => client.ResumeWorkflowAsync("", cancellation: TestContext.Current.CancellationToken)); + await Assert.ThrowsAsync(() => client.PurgeInstanceAsync("", TestContext.Current.CancellationToken)); - await client.TerminateWorkflowAsync("i", output: "o"); - await client.SuspendWorkflowAsync("i", reason: "r1"); - await client.ResumeWorkflowAsync("i", reason: "r2"); - var purged = await client.PurgeInstanceAsync("i"); + await client.TerminateWorkflowAsync("i", output: "o", cancellation: TestContext.Current.CancellationToken); + await client.SuspendWorkflowAsync("i", reason: "r1", cancellation: TestContext.Current.CancellationToken); + await client.ResumeWorkflowAsync("i", reason: "r2", cancellation: TestContext.Current.CancellationToken); + var purged = await client.PurgeInstanceAsync("i", TestContext.Current.CancellationToken); Assert.Equal("i", inner.LastTerminateInstanceId); Assert.Equal("i", inner.LastSuspendInstanceId); @@ -217,7 +217,7 @@ public async Task ListInstanceIdsAsync_ShouldForwardToInnerClient() var inner = new CapturingWorkflowClient { ListInstanceIdsResult = expectedPage }; var client = new DaprWorkflowClient(inner); - var result = await client.ListInstanceIdsAsync(continuationToken: "token", pageSize: 10); + var result = await client.ListInstanceIdsAsync(continuationToken: "token", pageSize: 10, cancellation: TestContext.Current.CancellationToken); Assert.Equal(expectedPage, result); Assert.Equal("token", inner.LastListContinuationToken); @@ -230,7 +230,7 @@ public async Task GetInstanceHistoryAsync_ShouldThrowArgumentException_WhenInsta var inner = new CapturingWorkflowClient(); var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.GetInstanceHistoryAsync("")); + await Assert.ThrowsAsync(() => client.GetInstanceHistoryAsync("", TestContext.Current.CancellationToken)); } [Fact] @@ -243,7 +243,7 @@ public async Task GetInstanceHistoryAsync_ShouldForwardToInnerClient() var inner = new CapturingWorkflowClient { GetInstanceHistoryResult = events }; var client = new DaprWorkflowClient(inner); - var result = await client.GetInstanceHistoryAsync("i"); + var result = await client.GetInstanceHistoryAsync("i", TestContext.Current.CancellationToken); Assert.Single(result); Assert.Equal("i", inner.LastGetHistoryInstanceId); @@ -255,7 +255,7 @@ public async Task RerunWorkflowFromEventAsync_ShouldThrowArgumentException_WhenS var inner = new CapturingWorkflowClient(); var client = new DaprWorkflowClient(inner); - await Assert.ThrowsAsync(() => client.RerunWorkflowFromEventAsync("", 1)); + await Assert.ThrowsAsync(() => client.RerunWorkflowFromEventAsync("", 1, cancellation: TestContext.Current.CancellationToken)); } [Fact] @@ -265,7 +265,7 @@ public async Task RerunWorkflowFromEventAsync_ShouldForwardToInnerClient() var client = new DaprWorkflowClient(inner); var options = new RerunWorkflowFromEventOptions { NewInstanceId = "custom-id" }; - var result = await client.RerunWorkflowFromEventAsync("source-id", 42, options); + var result = await client.RerunWorkflowFromEventAsync("source-id", 42, options, TestContext.Current.CancellationToken); Assert.Equal("new-id", result); Assert.Equal("source-id", inner.LastRerunSourceInstanceId); diff --git a/test/Dapr.Workflow.Test/Worker/Internal/WorkflowOrchestrationContextTests.cs b/test/Dapr.Workflow.Test/Worker/Internal/WorkflowOrchestrationContextTests.cs index 66ad2ba32..0c89afee1 100644 --- a/test/Dapr.Workflow.Test/Worker/Internal/WorkflowOrchestrationContextTests.cs +++ b/test/Dapr.Workflow.Test/Worker/Internal/WorkflowOrchestrationContextTests.cs @@ -108,7 +108,7 @@ public async Task CallChildWorkflowAsync_ShouldComplete_WhenRuntimeUsesCreatedEv context.ProcessEvents(history, isReplaying: true); - var result = await childTask.WaitAsync(TimeSpan.FromSeconds(2)); + var result = await childTask.WaitAsync(TimeSpan.FromSeconds(2), TestContext.Current.CancellationToken); Assert.Equal(21, result); Assert.Empty(context.PendingActions); } @@ -524,7 +524,7 @@ public async Task WaitForExternalEventAsync_ShouldReturnDeserializedValue_WhenEv loggerFactory: NullLoggerFactory.Instance, tracker); - var task = context.WaitForExternalEventAsync("myevent"); + var task = context.WaitForExternalEventAsync("myevent", TestContext.Current.CancellationToken); context.ProcessEvents(history, true); var value = await task; @@ -790,11 +790,11 @@ public void CreateReplaySafeLogger_ShouldReturnLoggerThatIsDisabledDuringReplay( _ = context.CallActivityAsync("Any"); // consumes 1 history event context.ProcessEvents(history, true); Assert.True(context.IsReplaying); - Assert.False(logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)); + Assert.False(logger.IsEnabled(LogLevel.Information)); context.ProcessEvents([], false); Assert.False(context.IsReplaying); - Assert.True(logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)); + Assert.True(logger.IsEnabled(LogLevel.Information)); } [Fact] @@ -1064,7 +1064,7 @@ public async Task WaitForExternalEventAsync_ShouldReturnDefault_WhenEventInHisto loggerFactory: NullLoggerFactory.Instance, tracker); - var task = context.WaitForExternalEventAsync("MyEvent"); + var task = context.WaitForExternalEventAsync("MyEvent", TestContext.Current.CancellationToken); context.ProcessEvents(history, true); var value = await task; @@ -1265,13 +1265,13 @@ public void CreateReplaySafeLogger_TypeAndGenericOverloads_ShouldBehaveLikeCateg _ = context.CallActivityAsync("Any"); // consumes 1 history event context.ProcessEvents(history, true); Assert.True(context.IsReplaying); - Assert.False(typeLogger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)); - Assert.False(genericLogger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)); + Assert.False(typeLogger.IsEnabled(LogLevel.Information)); + Assert.False(genericLogger.IsEnabled(LogLevel.Information)); context.ProcessEvents([], false); Assert.False(context.IsReplaying); - Assert.True(typeLogger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)); - Assert.True(genericLogger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)); + Assert.True(typeLogger.IsEnabled(LogLevel.Information)); + Assert.True(genericLogger.IsEnabled(LogLevel.Information)); } private sealed class MyExampleType @@ -1324,20 +1324,20 @@ public void Dispose() { } } } - private sealed class AlwaysEnabledLoggerFactory : Microsoft.Extensions.Logging.ILoggerFactory + private sealed class AlwaysEnabledLoggerFactory : ILoggerFactory { - public void AddProvider(Microsoft.Extensions.Logging.ILoggerProvider provider) { } - public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName) => new AlwaysEnabledLogger(); + public void AddProvider(ILoggerProvider provider) { } + public ILogger CreateLogger(string categoryName) => new AlwaysEnabledLogger(); public void Dispose() { } } - private sealed class AlwaysEnabledLogger : Microsoft.Extensions.Logging.ILogger + private sealed class AlwaysEnabledLogger : ILogger { public IDisposable? BeginScope(TState state) where TState : notnull => null; - public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => true; + public bool IsEnabled(LogLevel logLevel) => true; public void Log( - Microsoft.Extensions.Logging.LogLevel logLevel, - Microsoft.Extensions.Logging.EventId eventId, + LogLevel logLevel, + EventId eventId, TState state, Exception? exception, Func formatter) diff --git a/test/Dapr.Workflow.Versioning.Runtime.Test/Dapr.Workflow.Versioning.Runtime.Test.csproj b/test/Dapr.Workflow.Versioning.Runtime.Test/Dapr.Workflow.Versioning.Runtime.Test.csproj index 265c8180f..e80b5cca2 100644 --- a/test/Dapr.Workflow.Versioning.Runtime.Test/Dapr.Workflow.Versioning.Runtime.Test.csproj +++ b/test/Dapr.Workflow.Versioning.Runtime.Test/Dapr.Workflow.Versioning.Runtime.Test.csproj @@ -12,8 +12,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 835f82a70..5538aa9cf 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -6,13 +6,18 @@ $(RepoRoot)bin\$(Configuration)\test\$(MSBuildProjectName)\ - false - $(NoWarn);DAPR_CONVERSATION;DAPR_JOBS;DAPR_DISTRIBUTEDLOCK;DAPR_CRYPTOGRAPHY + Exe + + + + + true + $(NoWarn);CS8002;DAPR_CONVERSATION;DAPR_JOBS;DAPR_DISTRIBUTEDLOCK;DAPR_CRYPTOGRAPHY - \ No newline at end of file +