diff --git a/Directory.Build.props b/Directory.Build.props index 5edddae9815..8cf58266249 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -36,9 +36,8 @@ - - $(NoWarn);xUnit2031;xUnit1051 + $(NoWarn);xUnit2031; diff --git a/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs b/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs index e01745723b2..e5cc172d0c1 100644 --- a/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs +++ b/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderChatClientExtensionsTests.cs @@ -214,7 +214,7 @@ public async Task CanConfigurePipelineAsync(bool useKeyed) host.Services.GetRequiredKeyedService("openai_chatclient") : host.Services.GetRequiredService(); - var completion = await client.GetResponseAsync("Whatever"); + var completion = await client.GetResponseAsync("Whatever", cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("Hello from middleware", completion.Text); static Task TestMiddleware(IEnumerable list, ChatOptions? options, IChatClient client, CancellationToken token) diff --git a/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs b/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs index b35d871780b..7f6e13093f4 100644 --- a/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs +++ b/tests/Aspire.Azure.AI.OpenAI.Tests/AspireAzureOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs @@ -214,7 +214,7 @@ public async Task CanConfigurePipelineAsync(bool useKeyed) host.Services.GetRequiredKeyedService>>("openai_embeddinggenerator") : host.Services.GetRequiredService>>(); - var vector = await generator.GenerateEmbeddingVectorAsync("Hello"); + var vector = await generator.GenerateEmbeddingVectorAsync("Hello", cancellationToken: TestContext.Current.CancellationToken); Assert.Equal(1.23f, vector.ToArray().Single()); } diff --git a/tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj b/tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj index 24502b76997..1e72c1faefd 100644 --- a/tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj +++ b/tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj @@ -1,4 +1,4 @@ - + $(DefaultTargetFramework) @@ -9,6 +9,7 @@ false false + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Components.Common.Tests/ConformanceTests.cs b/tests/Aspire.Components.Common.Tests/ConformanceTests.cs index c6f3523a1d9..deea5d34543 100644 --- a/tests/Aspire.Components.Common.Tests/ConformanceTests.cs +++ b/tests/Aspire.Components.Common.Tests/ConformanceTests.cs @@ -135,7 +135,8 @@ await healthCheckService.CheckHealthAsync(healthCheckRegistration => { registeredNames.Add(healthCheckRegistration.Name); return false; - }).ConfigureAwait(false); + }, + TestContext.Current.CancellationToken).ConfigureAwait(false); #pragma warning restore xUnit1030 // Do not call ConfigureAwait(false) in test method Assert.Equal(2, registeredNames.Count); @@ -320,7 +321,7 @@ public async Task HealthCheckReportsExpectedStatus(string? key) HealthCheckService healthCheckService = host.Services.GetRequiredService(); #pragma warning disable xUnit1030 // Do not call ConfigureAwait(false) in test method - HealthReport healthReport = await healthCheckService.CheckHealthAsync().ConfigureAwait(false); + HealthReport healthReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken).ConfigureAwait(false); #pragma warning restore xUnit1030 // Do not call ConfigureAwait(false) in test method HealthStatus expected = CanConnectToServer ? HealthStatus.Healthy : HealthStatus.Unhealthy; diff --git a/tests/Aspire.Confluent.Kafka.Tests/Aspire8MetricsTests.cs b/tests/Aspire.Confluent.Kafka.Tests/Aspire8MetricsTests.cs index 3ec51d00c56..3caeac9b2ef 100644 --- a/tests/Aspire.Confluent.Kafka.Tests/Aspire8MetricsTests.cs +++ b/tests/Aspire.Confluent.Kafka.Tests/Aspire8MetricsTests.cs @@ -38,7 +38,7 @@ public async Task ExposesStatisticsAsCountersAndGauge_InitializeCounters(TestVar } using var host = builder.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var metricsChannel = host.Services.GetRequiredService(ReflectionHelpers.MetricsChannelType.Value); var writer = GetMetricsChannelWriter(metricsChannel)!; @@ -61,14 +61,14 @@ public async Task ExposesStatisticsAsCountersAndGauge_InitializeCounters(TestVar } await Task.WhenAll( - collectorNetworkTx.WaitForMeasurementsAsync(statistics.Count), - collectorNetworkTransmitted.WaitForMeasurementsAsync(statistics.Count), - collectorNetworkRx.WaitForMeasurementsAsync(statistics.Count), - collectorNetworkReceived.WaitForMeasurementsAsync(statistics.Count), - collectorMessageTx.WaitForMeasurementsAsync(statistics.Count), - collectorMessageTransmitted.WaitForMeasurementsAsync(statistics.Count), - collectorMessageRx.WaitForMeasurementsAsync(statistics.Count), - collectorMessageReceived.WaitForMeasurementsAsync(statistics.Count) + collectorNetworkTx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorNetworkTransmitted.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorNetworkRx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorNetworkReceived.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageTx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageTransmitted.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageRx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageReceived.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken) ); collectorConsumerQueueMessageCount.RecordObservableInstruments(); @@ -153,7 +153,7 @@ public async Task ExposesStatisticsAsCountersAndGauge_AggregateCountersByName(Te } using var host = builder.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var metricsChannel = host.Services.GetRequiredService(ReflectionHelpers.MetricsChannelType.Value); var writer = GetMetricsChannelWriter(metricsChannel)!; @@ -176,14 +176,14 @@ public async Task ExposesStatisticsAsCountersAndGauge_AggregateCountersByName(Te } await Task.WhenAll( - collectorNetworkTx.WaitForMeasurementsAsync(statistics.Count), - collectorNetworkTransmitted.WaitForMeasurementsAsync(statistics.Count), - collectorNetworkRx.WaitForMeasurementsAsync(statistics.Count), - collectorNetworkReceived.WaitForMeasurementsAsync(statistics.Count), - collectorMessageTx.WaitForMeasurementsAsync(statistics.Count), - collectorMessageTransmitted.WaitForMeasurementsAsync(statistics.Count), - collectorMessageRx.WaitForMeasurementsAsync(statistics.Count), - collectorMessageReceived.WaitForMeasurementsAsync(statistics.Count) + collectorNetworkTx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorNetworkTransmitted.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorNetworkRx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorNetworkReceived.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageTx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageTransmitted.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageRx.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken), + collectorMessageReceived.WaitForMeasurementsAsync(statistics.Count, TestContext.Current.CancellationToken) ); collectorConsumerQueueMessageCount.RecordObservableInstruments(); diff --git a/tests/Aspire.Confluent.Kafka.Tests/OtelMetricsTests.cs b/tests/Aspire.Confluent.Kafka.Tests/OtelMetricsTests.cs index e05288e8f23..d7000e83da5 100644 --- a/tests/Aspire.Confluent.Kafka.Tests/OtelMetricsTests.cs +++ b/tests/Aspire.Confluent.Kafka.Tests/OtelMetricsTests.cs @@ -60,7 +60,7 @@ public async Task EnsureMetricsAreProducedAsync(bool useKeyed) builder.Services.AddOpenTelemetry().WithMetrics(meterProvider => meterProvider.AddInMemoryExporter(metrics)); using var host = builder.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); IGrouping[] groups; string topic = $"otel-topic-{Guid.NewGuid()}"; @@ -90,7 +90,7 @@ public async Task EnsureMetricsAreProducedAsync(bool useKeyed) int j = 0; while (true) { - var consumerResult = consumer.Consume(); + var consumerResult = consumer.Consume(TestContext.Current.CancellationToken); if (consumerResult == null) { continue; @@ -108,7 +108,7 @@ public async Task EnsureMetricsAreProducedAsync(bool useKeyed) host.Services.GetRequiredService().EnsureMetricsAreFlushed(); - await host.StopAsync(); + await host.StopAsync(TestContext.Current.CancellationToken); groups = metrics.Where(x => x.MeterName == "OpenTelemetry.Instrumentation.ConfluentKafka") .GroupBy(x => x.Name).ToArray(); diff --git a/tests/Aspire.Confluent.Kafka.Tests/OtelTracesTests.cs b/tests/Aspire.Confluent.Kafka.Tests/OtelTracesTests.cs index 27f4c2fab2d..c4d55bd006c 100644 --- a/tests/Aspire.Confluent.Kafka.Tests/OtelTracesTests.cs +++ b/tests/Aspire.Confluent.Kafka.Tests/OtelTracesTests.cs @@ -62,7 +62,7 @@ public async Task EnsureTracesAreProducedAsync(bool useKeyed) builder.Services.AddOpenTelemetry().WithTracing(traceProviderBuilder => traceProviderBuilder.AddInMemoryExporter(activities)); using var host = builder.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); string topic = $"otel-topic-{Guid.NewGuid()}"; using (var producer = useKeyed @@ -95,7 +95,7 @@ public async Task EnsureTracesAreProducedAsync(bool useKeyed) int j = 0; while (true) { - var consumerResult = consumer.Consume(); + var consumerResult = consumer.Consume(TestContext.Current.CancellationToken); if (consumerResult == null) { continue; @@ -113,6 +113,6 @@ public async Task EnsureTracesAreProducedAsync(bool useKeyed) Assert.Equal(5, activities.Where(x => x.OperationName == $"{topic} receive").Count()); - await host.StopAsync(); + await host.StopAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Aspire.Dashboard.Components.Tests/Layout/MainLayoutTests.cs b/tests/Aspire.Dashboard.Components.Tests/Layout/MainLayoutTests.cs index afe1bf75b4d..950ea4293f5 100644 --- a/tests/Aspire.Dashboard.Components.Tests/Layout/MainLayoutTests.cs +++ b/tests/Aspire.Dashboard.Components.Tests/Layout/MainLayoutTests.cs @@ -16,7 +16,8 @@ using Microsoft.FluentUI.AspNetCore.Components; using Microsoft.FluentUI.AspNetCore.Components.Components.Tooltip; using Xunit; - +using TestContext = Xunit.TestContext; + namespace Aspire.Dashboard.Components.Tests.Layout; [UseCulture("en-US")] @@ -72,13 +73,13 @@ public async Task OnInitialize_UnsecuredOtlp_NotDismissed_DisplayMessageBar() }); // Assert - await messageShownTcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + await messageShownTcs.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); Assert.NotNull(message); message.Close(); - Assert.True(await dismissedSettingSetTcs.Task.WaitAsync(TimeSpan.FromSeconds(5))); + Assert.True(await dismissedSettingSetTcs.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken)); } [Fact] @@ -116,8 +117,8 @@ public async Task OnInitialize_UnsecuredOtlp_Dismissed_NoMessageBar() }); // Assert - var timeoutTask = Task.Delay(100); - var completedTask = await Task.WhenAny(messageShownTcs.Task, timeoutTask).WaitAsync(TimeSpan.FromSeconds(5)); + var timeoutTask = Task.Delay(100, TestContext.Current.CancellationToken); + var completedTask = await Task.WhenAny(messageShownTcs.Task, timeoutTask).WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); // It's hard to test something not happening. // In this case of checking for a message, apply a small display and then double check that no message was displayed. diff --git a/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs b/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs index 5882237d038..631eba0d52d 100644 --- a/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs +++ b/tests/Aspire.Dashboard.Components.Tests/Pages/ConsoleLogsTests.cs @@ -25,6 +25,7 @@ using Microsoft.Extensions.Options; using Microsoft.FluentUI.AspNetCore.Components; using Xunit; +using TestContext = Xunit.TestContext; namespace Aspire.Dashboard.Components.Tests.Pages; @@ -91,7 +92,7 @@ public async Task ResourceName_SubscribeOnLoadAndChange_SubscribeConsoleLogsOnce logger.LogInformation("Waiting for finish message."); cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsFinishedWatchingLogs)]); - var subscribedResourceName1 = await subscribedResourceNamesChannel.Reader.ReadAsync().DefaultTimeout(); + var subscribedResourceName1 = await subscribedResourceNamesChannel.Reader.ReadAsync(TestContext.Current.CancellationToken).DefaultTimeout(); Assert.Equal("test-resource", subscribedResourceName1); navigationManager.LocationChanged += (sender, e) => @@ -117,11 +118,11 @@ public async Task ResourceName_SubscribeOnLoadAndChange_SubscribeConsoleLogsOnce cut.WaitForState(() => instance.PageViewModel.SelectedResource == testResource2); cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsWatchingLogs)]); - var subscribedResourceName2 = await subscribedResourceNamesChannel.Reader.ReadAsync().DefaultTimeout(); + var subscribedResourceName2 = await subscribedResourceNamesChannel.Reader.ReadAsync(TestContext.Current.CancellationToken).DefaultTimeout(); Assert.Equal("test-resource2", subscribedResourceName2); subscribedResourceNamesChannel.Writer.Complete(); - Assert.False(await subscribedResourceNamesChannel.Reader.WaitToReadAsync().DefaultTimeout()); + Assert.False(await subscribedResourceNamesChannel.Reader.WaitToReadAsync(TestContext.Current.CancellationToken).DefaultTimeout()); } [Fact] diff --git a/tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj b/tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj index 27287dbd9d8..8f07ab8f671 100644 --- a/tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj +++ b/tests/Aspire.Dashboard.Tests/Aspire.Dashboard.Tests.csproj @@ -5,7 +5,14 @@ - $(NoWarn);CS8002 + + $(NoWarn);CS8002;xUnit1051 true true diff --git a/tests/Aspire.Elastic.Clients.Elasticsearch.Tests/AspireElasticClientExtensionsTest.cs b/tests/Aspire.Elastic.Clients.Elasticsearch.Tests/AspireElasticClientExtensionsTest.cs index 2e9e735e25b..e4cde401ac9 100644 --- a/tests/Aspire.Elastic.Clients.Elasticsearch.Tests/AspireElasticClientExtensionsTest.cs +++ b/tests/Aspire.Elastic.Clients.Elasticsearch.Tests/AspireElasticClientExtensionsTest.cs @@ -57,7 +57,7 @@ public async Task AddElasticsearchClient_HealthCheckShouldBeRegisteredWhenEnable var healthCheckService = host.Services.GetRequiredService(); - var healthCheckReport = await healthCheckService.CheckHealthAsync(); + var healthCheckReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken); var healthCheckName = useKeyed ? $"Elastic.Clients.Elasticsearch_{key}" : "Elastic.Clients.Elasticsearch"; diff --git a/tests/Aspire.Hosting.Analyzers.Tests/CombinationsAnalyzerTests.cs b/tests/Aspire.Hosting.Analyzers.Tests/CombinationsAnalyzerTests.cs index c7777cb31da..768ff657ccc 100644 --- a/tests/Aspire.Hosting.Analyzers.Tests/CombinationsAnalyzerTests.cs +++ b/tests/Aspire.Hosting.Analyzers.Tests/CombinationsAnalyzerTests.cs @@ -41,7 +41,7 @@ public static void AddMultiple(this IDistributedApplicationBuilder builder, [Res CompilerError(diagnostic.Id).WithLocation(8, 5).WithMessage(message2) ]); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -74,6 +74,6 @@ public static void AddMultiple(this IDistributedApplicationBuilder builder, [Res CompilerError(diagnostic.Id).WithLocation(6, 21).WithMessage(message2) ]); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Aspire.Hosting.Analyzers.Tests/EndpointNameAnalyzerTests.cs b/tests/Aspire.Hosting.Analyzers.Tests/EndpointNameAnalyzerTests.cs index 388787ef229..6dbf1f5c9d3 100644 --- a/tests/Aspire.Hosting.Analyzers.Tests/EndpointNameAnalyzerTests.cs +++ b/tests/Aspire.Hosting.Analyzers.Tests/EndpointNameAnalyzerTests.cs @@ -27,7 +27,7 @@ public async Task EndpointNameInvalid(string endpointName) """, [CompilerError(diagnostic.Id).WithLocation(6, 37).WithMessage(message)]); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -66,7 +66,7 @@ public static IResourceBuilder WithEndpoints( CompilerError(diagnostic.Id).WithLocation(9, 9).WithMessage(message2) ]); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -82,7 +82,7 @@ public async Task EndpointNameValid(string endpointName) .WithEndpoint(port: 1234, name: "{{endpointName}}"); """, []); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -112,6 +112,6 @@ public static IResourceBuilder WithEndpoints( } """, []); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Aspire.Hosting.Analyzers.Tests/ResourceNameAnalyzerTests.cs b/tests/Aspire.Hosting.Analyzers.Tests/ResourceNameAnalyzerTests.cs index 8c72a549ecd..78f192a470e 100644 --- a/tests/Aspire.Hosting.Analyzers.Tests/ResourceNameAnalyzerTests.cs +++ b/tests/Aspire.Hosting.Analyzers.Tests/ResourceNameAnalyzerTests.cs @@ -26,7 +26,7 @@ public async Task ResourceNameInvalid(string resourceName) """, [CompilerError(diagnostic.Id).WithLocation(5, 22).WithMessage(message)]); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -61,7 +61,7 @@ public static void AddMultipleParameters(this IDistributedApplicationBuilder bui CompilerError(diagnostic.Id).WithLocation(8, 5).WithMessage(message2) ]); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -76,7 +76,7 @@ public async Task ResourceNameValid(string resourceName) builder.AddParameter("{{resourceName}}"); """, []); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } [Theory] @@ -102,6 +102,6 @@ public static void AddMultipleParameters(this IDistributedApplicationBuilder bui } """, []); - await test.RunAsync(); + await test.RunAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj b/tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj index 291bd8eca75..8d4181e09e1 100644 --- a/tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj +++ b/tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj b/tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj index a24425ab924..b3156bed453 100644 --- a/tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj +++ b/tests/Aspire.Hosting.Containers.Tests/Aspire.Hosting.Containers.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.Docker.Tests/Aspire.Hosting.Docker.Tests.csproj b/tests/Aspire.Hosting.Docker.Tests/Aspire.Hosting.Docker.Tests.csproj index f5cb482b6ef..4efc8d4b447 100644 --- a/tests/Aspire.Hosting.Docker.Tests/Aspire.Hosting.Docker.Tests.csproj +++ b/tests/Aspire.Hosting.Docker.Tests/Aspire.Hosting.Docker.Tests.csproj @@ -2,7 +2,7 @@ $(DefaultTargetFramework) - $(NoWarn);ASPIREHOSTINGPYTHON001; + $(NoWarn);ASPIREHOSTINGPYTHON001;xUnit1051 + $(NoWarn);CS8002;xUnit1051 diff --git a/tests/Aspire.Hosting.MongoDB.Tests/Aspire.Hosting.MongoDB.Tests.csproj b/tests/Aspire.Hosting.MongoDB.Tests/Aspire.Hosting.MongoDB.Tests.csproj index 895bf53fe89..97f0bd30efa 100644 --- a/tests/Aspire.Hosting.MongoDB.Tests/Aspire.Hosting.MongoDB.Tests.csproj +++ b/tests/Aspire.Hosting.MongoDB.Tests/Aspire.Hosting.MongoDB.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.MySql.Tests/Aspire.Hosting.MySql.Tests.csproj b/tests/Aspire.Hosting.MySql.Tests/Aspire.Hosting.MySql.Tests.csproj index 04844332767..5e05c81b101 100644 --- a/tests/Aspire.Hosting.MySql.Tests/Aspire.Hosting.MySql.Tests.csproj +++ b/tests/Aspire.Hosting.MySql.Tests/Aspire.Hosting.MySql.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.Nats.Tests/Aspire.Hosting.Nats.Tests.csproj b/tests/Aspire.Hosting.Nats.Tests/Aspire.Hosting.Nats.Tests.csproj index 497bfc379ec..d30e5458871 100644 --- a/tests/Aspire.Hosting.Nats.Tests/Aspire.Hosting.Nats.Tests.csproj +++ b/tests/Aspire.Hosting.Nats.Tests/Aspire.Hosting.Nats.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.Oracle.Tests/Aspire.Hosting.Oracle.Tests.csproj b/tests/Aspire.Hosting.Oracle.Tests/Aspire.Hosting.Oracle.Tests.csproj index 0dc69462944..b853329a230 100644 --- a/tests/Aspire.Hosting.Oracle.Tests/Aspire.Hosting.Oracle.Tests.csproj +++ b/tests/Aspire.Hosting.Oracle.Tests/Aspire.Hosting.Oracle.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.PostgreSQL.Tests/Aspire.Hosting.PostgreSQL.Tests.csproj b/tests/Aspire.Hosting.PostgreSQL.Tests/Aspire.Hosting.PostgreSQL.Tests.csproj index 75a8f514a1c..2b87611a605 100644 --- a/tests/Aspire.Hosting.PostgreSQL.Tests/Aspire.Hosting.PostgreSQL.Tests.csproj +++ b/tests/Aspire.Hosting.PostgreSQL.Tests/Aspire.Hosting.PostgreSQL.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs b/tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs index e0c04ba7a81..cdcb263eb85 100644 --- a/tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs +++ b/tests/Aspire.Hosting.Python.Tests/AddPythonAppTests.cs @@ -99,11 +99,11 @@ public async Task PythonResourceFinishesSuccessfully() using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); - await app.ResourceNotifications.WaitForResourceAsync("pyproj", "Finished").WaitAsync(TimeSpan.FromSeconds(30)); + await app.ResourceNotifications.WaitForResourceAsync("pyproj", "Finished", TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken); - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); // If we don't throw, clean up the directories. Directory.Delete(projectDirectory, true); diff --git a/tests/Aspire.Hosting.Qdrant.Tests/Aspire.Hosting.Qdrant.Tests.csproj b/tests/Aspire.Hosting.Qdrant.Tests/Aspire.Hosting.Qdrant.Tests.csproj index aa5a474f2d8..4398ff2377c 100644 --- a/tests/Aspire.Hosting.Qdrant.Tests/Aspire.Hosting.Qdrant.Tests.csproj +++ b/tests/Aspire.Hosting.Qdrant.Tests/Aspire.Hosting.Qdrant.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.RabbitMQ.Tests/Aspire.Hosting.RabbitMQ.Tests.csproj b/tests/Aspire.Hosting.RabbitMQ.Tests/Aspire.Hosting.RabbitMQ.Tests.csproj index b89475a5de9..1658562834b 100644 --- a/tests/Aspire.Hosting.RabbitMQ.Tests/Aspire.Hosting.RabbitMQ.Tests.csproj +++ b/tests/Aspire.Hosting.RabbitMQ.Tests/Aspire.Hosting.RabbitMQ.Tests.csproj @@ -2,6 +2,7 @@ $(DefaultTargetFramework) + $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs b/tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs index 53c539abff0..ec4e3f653bf 100644 --- a/tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs +++ b/tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs @@ -122,7 +122,7 @@ public async Task RedisCreatesConnectionStringWithDefaultPassword() var appModel = app.Services.GetRequiredService(); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("{myRedis.bindings.tcp.host}:{myRedis.bindings.tcp.port},password={myRedis-password.value}", connectionStringResource.ConnectionStringExpression.ValueExpression); Assert.StartsWith("localhost:2000", connectionString); } @@ -266,7 +266,7 @@ public async Task WithRedisInsightProducesCorrectEnvironmentVariables() redis1.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 5001)); redis2.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 5002)); - await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService())); + await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService()), TestContext.Current.CancellationToken); var redisInsight = Assert.Single(builder.Resources.OfType()); var envs = await redisInsight.GetEnvironmentVariableValuesAsync(); @@ -408,7 +408,7 @@ public async Task VerifyRedisResourceWithPassword() var containerResource = Assert.Single(appModel.Resources.OfType()); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("{myRedis.bindings.tcp.host}:{myRedis.bindings.tcp.port},password={pass.value}", connectionStringResource.ConnectionStringExpression.ValueExpression); Assert.StartsWith($"localhost:5001,password={password}", connectionString); } @@ -423,7 +423,7 @@ public async Task SingleRedisInstanceWithoutPasswordProducesCorrectRedisHostsVar // Add fake allocated endpoints. redis.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 5001)); - await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService())); + await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService()), TestContext.Current.CancellationToken); var commander = builder.Resources.Single(r => r.Name.EndsWith("-commander")); @@ -447,7 +447,7 @@ public async Task SingleRedisInstanceWithPasswordProducesCorrectRedisHostsVariab // Add fake allocated endpoints. redis.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 5001)); - await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService())); + await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService()), TestContext.Current.CancellationToken); var commander = builder.Resources.Single(r => r.Name.EndsWith("-commander")); @@ -468,7 +468,7 @@ public async Task MultipleRedisInstanceProducesCorrectRedisHostsVariable() redis1.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 5001)); redis2.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 5002, "host2")); - await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService())); + await builder.Eventing.PublishAsync(new(app.Services, app.Services.GetRequiredService()), TestContext.Current.CancellationToken); var commander = builder.Resources.Single(r => r.Name.EndsWith("-commander")); @@ -625,7 +625,7 @@ public async Task AddRedisContainerWithPasswordAnnotationMetadata() var containerResource = Assert.Single(appModel.Resources.OfType()); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("{myRedis.bindings.tcp.host}:{myRedis.bindings.tcp.port},password={pass.value}", connectionStringResource.ConnectionStringExpression.ValueExpression); Assert.StartsWith($"localhost:5001,password={password}", connectionString); } diff --git a/tests/Aspire.Hosting.Redis.Tests/RedisFunctionalTests.cs b/tests/Aspire.Hosting.Redis.Tests/RedisFunctionalTests.cs index b1e36bc1afd..265591c5979 100644 --- a/tests/Aspire.Hosting.Redis.Tests/RedisFunctionalTests.cs +++ b/tests/Aspire.Hosting.Redis.Tests/RedisFunctionalTests.cs @@ -62,7 +62,7 @@ public async Task VerifyWaitForOnRedisBlocksDependentResources() await pendingStart; - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } [Fact] @@ -77,15 +77,15 @@ public async Task VerifyRedisCommanderResource() using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForTextAsync("Redis Connection", resourceName: commanderBuilder.Resource.Name); + await app.WaitForTextAsync("Redis Connection", resourceName: commanderBuilder.Resource.Name, TestContext.Current.CancellationToken); var client = app.CreateHttpClient(commanderBuilder.Resource.Name, "http"); var endpoint = redis.GetEndpoint("tcp"); var path = $"/apiv2/server/R:{redis.Resource.Name}:{endpoint.TargetPort}:0/info"; - var response = await client.GetAsync(path); + var response = await client.GetAsync(path, TestContext.Current.CancellationToken); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } @@ -99,20 +99,20 @@ public async Task VerifyRedisResource() using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis.Resource.Name}"] = await redis.Resource.GetConnectionStringAsync() + [$"ConnectionStrings:{redis.Resource.Name}"] = await redis.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken) }); hb.AddRedisClient(redis.Resource.Name); using var host = hb.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -140,10 +140,10 @@ public async Task VerifyWithRedisInsightImportDatabases() using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var rns = app.Services.GetRequiredService(); - await rns.WaitForResourceAsync(redisInsightBuilder.Resource.Name, KnownResourceStates.Running).WaitAsync(cts.Token); + await rns.WaitForResourceAsync(redisInsightBuilder.Resource.Name, KnownResourceStates.Running, TestContext.Current.CancellationToken).WaitAsync(cts.Token); var client = app.CreateHttpClient(redisInsightBuilder.Resource.Name, "http"); @@ -197,21 +197,21 @@ public async Task WithDataVolumeShouldPersistStateBetweenUsages() using (var app = builder1.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); // BGSAVE is only available in admin mode, enable it for this instance hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis1.Resource.Name}"] = $"{await redis1.Resource.GetConnectionStringAsync()},allowAdmin=true" + [$"ConnectionStrings:{redis1.Resource.Name}"] = $"{await redis1.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken)},allowAdmin=true" }); hb.AddRedisClient(redis1.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -226,7 +226,7 @@ public async Task WithDataVolumeShouldPersistStateBetweenUsages() } // Stops the container, or the Volume would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } using var builder2 = TestDistributedApplicationBuilder.CreateWithTestContainerRegistry(testOutputHelper); @@ -234,20 +234,20 @@ public async Task WithDataVolumeShouldPersistStateBetweenUsages() using (var app = builder2.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis2.Resource.Name}"] = await redis2.Resource.GetConnectionStringAsync() + [$"ConnectionStrings:{redis2.Resource.Name}"] = await redis2.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken) }); hb.AddRedisClient(redis2.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -259,7 +259,7 @@ public async Task WithDataVolumeShouldPersistStateBetweenUsages() } // Stops the container, or the Volume would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } DockerUtils.AttemptDeleteDockerVolume(volumeName); @@ -280,21 +280,21 @@ public async Task WithDataBindMountShouldPersistStateBetweenUsages() using (var app = builder1.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); // BGSAVE is only available in admin mode, enable it for this instance hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis1.Resource.Name}"] = $"{await redis1.Resource.GetConnectionStringAsync()},allowAdmin=true" + [$"ConnectionStrings:{redis1.Resource.Name}"] = $"{await redis1.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken)},allowAdmin=true" }); hb.AddRedisClient(redis1.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -308,7 +308,7 @@ public async Task WithDataBindMountShouldPersistStateBetweenUsages() await redisClient.GetServers().First().SaveAsync(SaveType.BackgroundSave); } - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } using var builder2 = TestDistributedApplicationBuilder.CreateWithTestContainerRegistry(testOutputHelper); @@ -316,20 +316,20 @@ public async Task WithDataBindMountShouldPersistStateBetweenUsages() using (var app = builder2.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis2.Resource.Name}"] = await redis2.Resource.GetConnectionStringAsync() + [$"ConnectionStrings:{redis2.Resource.Name}"] = await redis2.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken) }); hb.AddRedisClient(redis2.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -340,7 +340,7 @@ public async Task WithDataBindMountShouldPersistStateBetweenUsages() Assert.Equal("value", value); } - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } try @@ -364,21 +364,21 @@ public async Task PersistenceIsDisabledByDefault() using (var app = builder1.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); // BGSAVE is only available in admin mode, enable it for this instance hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis1.Resource.Name}"] = $"{await redis1.Resource.GetConnectionStringAsync()},allowAdmin=true" + [$"ConnectionStrings:{redis1.Resource.Name}"] = $"{await redis1.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken)},allowAdmin=true" }); hb.AddRedisClient(redis1.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -387,7 +387,7 @@ public async Task PersistenceIsDisabledByDefault() await db.StringSetAsync("key", "value"); } - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } using var builder2 = TestDistributedApplicationBuilder.CreateWithTestContainerRegistry(testOutputHelper); @@ -395,20 +395,20 @@ public async Task PersistenceIsDisabledByDefault() using (var app = builder2.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{redis2.Resource.Name}"] = await redis2.Resource.GetConnectionStringAsync() + [$"ConnectionStrings:{redis2.Resource.Name}"] = await redis2.Resource.GetConnectionStringAsync(TestContext.Current.CancellationToken) }); hb.AddRedisClient(redis2.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -419,7 +419,7 @@ public async Task PersistenceIsDisabledByDefault() Assert.True(value.IsNull); } - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } @@ -466,10 +466,10 @@ public async Task RedisInsightWithDataShouldPersistStateBetweenUsages(bool useVo using (var app = builder1.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var rns = app.Services.GetRequiredService(); - await rns.WaitForResourceAsync(redisInsightBuilder1.Resource.Name, KnownResourceStates.Running).WaitAsync(cts.Token); + await rns.WaitForResourceAsync(redisInsightBuilder1.Resource.Name, KnownResourceStates.Running, TestContext.Current.CancellationToken).WaitAsync(cts.Token); try { @@ -479,7 +479,7 @@ public async Task RedisInsightWithDataShouldPersistStateBetweenUsages(bool useVo finally { // Stops the container, or the Volume would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } @@ -501,10 +501,10 @@ public async Task RedisInsightWithDataShouldPersistStateBetweenUsages(bool useVo using (var app = builder2.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var rns = app.Services.GetRequiredService(); - await rns.WaitForResourceAsync(redisInsightBuilder2.Resource.Name, KnownResourceStates.Running).WaitAsync(cts.Token); + await rns.WaitForResourceAsync(redisInsightBuilder2.Resource.Name, KnownResourceStates.Running, TestContext.Current.CancellationToken).WaitAsync(cts.Token); try { @@ -514,7 +514,7 @@ public async Task RedisInsightWithDataShouldPersistStateBetweenUsages(bool useVo finally { // Stops the container, or the Volume would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } } @@ -602,7 +602,7 @@ public async Task WithRedisCommanderShouldWorkWithPassword() builder.Services.AddHttpClient(); using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var appModel = app.Services.GetRequiredService(); var redisCommander = Assert.Single(appModel.Resources.OfType()); @@ -617,7 +617,7 @@ public async Task WithRedisCommanderShouldWorkWithPassword() var clientFactory = app.Services.GetRequiredService(); var client = clientFactory.CreateClient(); - var httpResponse = await client.GetAsync(redisCommanderUrl!); + var httpResponse = await client.GetAsync(redisCommanderUrl!, TestContext.Current.CancellationToken); httpResponse.EnsureSuccessStatusCode(); } diff --git a/tests/Aspire.Hosting.Seq.Tests/AddSeqTests.cs b/tests/Aspire.Hosting.Seq.Tests/AddSeqTests.cs index 116d602af14..630d505e758 100644 --- a/tests/Aspire.Hosting.Seq.Tests/AddSeqTests.cs +++ b/tests/Aspire.Hosting.Seq.Tests/AddSeqTests.cs @@ -79,7 +79,7 @@ public async Task SeqCreatesConnectionString() var appModel = app.Services.GetRequiredService(); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("{mySeq.bindings.http.url}", connectionStringResource.ConnectionStringExpression.ValueExpression); Assert.StartsWith("http://localhost:2000", connectionString); } diff --git a/tests/Aspire.Hosting.Seq.Tests/SeqFunctionalTests.cs b/tests/Aspire.Hosting.Seq.Tests/SeqFunctionalTests.cs index a2d2cbd0c4c..1da1dcf2585 100644 --- a/tests/Aspire.Hosting.Seq.Tests/SeqFunctionalTests.cs +++ b/tests/Aspire.Hosting.Seq.Tests/SeqFunctionalTests.cs @@ -22,17 +22,17 @@ public async Task VerifySeqResource() using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForTextAsync("Seq listening on", seq.Resource.Name); + await app.WaitForTextAsync("Seq listening on", seq.Resource.Name, TestContext.Current.CancellationToken); - var seqUrl = await seq.Resource.ConnectionStringExpression.GetValueAsync(default); + var seqUrl = await seq.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); Assert.NotNull(seqUrl); var client = CreateClient(seqUrl); - await CreateTestDataAsync(client, default); + await CreateTestDataAsync(client, TestContext.Current.CancellationToken); } private static HttpClient CreateClient(string url) @@ -97,24 +97,24 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) using (var app = builder1.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForTextAsync("Seq listening on", seq1.Resource.Name); + await app.WaitForTextAsync("Seq listening on", seq1.Resource.Name, TestContext.Current.CancellationToken); try { - var seqUrl = await seq1.Resource.ConnectionStringExpression.GetValueAsync(default); + var seqUrl = await seq1.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); Assert.NotNull(seqUrl); var client = CreateClient(seqUrl); - await CreateTestDataAsync(client, default); + await CreateTestDataAsync(client, TestContext.Current.CancellationToken); } finally { // Stops the container, or the Volume would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } @@ -133,24 +133,24 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) using (var app = builder2.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForTextAsync("Seq listening on", seq2.Resource.Name); + await app.WaitForTextAsync("Seq listening on", seq2.Resource.Name, TestContext.Current.CancellationToken); try { - var seqUrl = await seq2.Resource.ConnectionStringExpression.GetValueAsync(default); + var seqUrl = await seq2.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); Assert.NotNull(seqUrl); var client = CreateClient(seqUrl); - await CreateTestDataAsync(client, default); + await CreateTestDataAsync(client, TestContext.Current.CancellationToken); } finally { // Stops the container, or the Volume would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Aspire.Hosting.SqlServer.Tests/AddSqlServerTests.cs b/tests/Aspire.Hosting.SqlServer.Tests/AddSqlServerTests.cs index 673cc2d2638..28a6c974673 100644 --- a/tests/Aspire.Hosting.SqlServer.Tests/AddSqlServerTests.cs +++ b/tests/Aspire.Hosting.SqlServer.Tests/AddSqlServerTests.cs @@ -91,7 +91,7 @@ public async Task SqlServerCreatesConnectionString() var appModel = app.Services.GetRequiredService(); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("Server=127.0.0.1,1433;User ID=sa;Password=p@ssw0rd1;TrustServerCertificate=true", connectionString); Assert.Equal("Server={sqlserver.bindings.tcp.host},{sqlserver.bindings.tcp.port};User ID=sa;Password={pass.value};TrustServerCertificate=true", connectionStringResource.ConnectionStringExpression.ValueExpression); @@ -114,7 +114,7 @@ public async Task SqlServerDatabaseCreatesConnectionString() var sqlResource = Assert.Single(appModel.Resources.OfType()); var connectionStringResource = (IResourceWithConnectionString)sqlResource; - var connectionString = await connectionStringResource.GetConnectionStringAsync(); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("Server=127.0.0.1,1433;User ID=sa;Password=p@ssw0rd1;TrustServerCertificate=true;Initial Catalog=mydb", connectionString); Assert.Equal("{sqlserver.connectionString};Initial Catalog=mydb", connectionStringResource.ConnectionStringExpression.ValueExpression); @@ -277,7 +277,7 @@ public async Task VerifySqlServerServerResourceWithPassword() var appModel = app.Services.GetRequiredService(); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("Server=127.0.0.1,1433;User ID=sa;Password=p@ssw0rd1;TrustServerCertificate=true", connectionString); Assert.Equal("Server={sqlserver.bindings.tcp.host},{sqlserver.bindings.tcp.port};User ID=sa;Password={pass.value};TrustServerCertificate=true", connectionStringResource.ConnectionStringExpression.ValueExpression); } diff --git a/tests/Aspire.Hosting.SqlServer.Tests/SqlServerFunctionalTests.cs b/tests/Aspire.Hosting.SqlServer.Tests/SqlServerFunctionalTests.cs index 1d3039532e4..e7e3b4d8da7 100644 --- a/tests/Aspire.Hosting.SqlServer.Tests/SqlServerFunctionalTests.cs +++ b/tests/Aspire.Hosting.SqlServer.Tests/SqlServerFunctionalTests.cs @@ -53,7 +53,7 @@ public async Task VerifyWaitForOnSqlServerBlocksDependentResources() await pendingStart; - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } [Fact] @@ -78,14 +78,14 @@ public async Task VerifySqlServerResource() var hb = Host.CreateApplicationBuilder(); - hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(default); + hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); hb.AddSqlServerDbContext(newDb.Resource.Name); hb.AddSqlServerClient(newDb.Resource.Name); using var host = hb.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); // Test SqlConnection await pipeline.ExecuteAsync(async token => @@ -174,7 +174,7 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) using var app1 = builder1.Build(); - await app1.StartAsync(); + await app1.StartAsync(TestContext.Current.CancellationToken); await app1.ResourceNotifications.WaitForResourceHealthyAsync(db1.Resource.Name, cts.Token); @@ -184,14 +184,14 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) hb1.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{db1.Resource.Name}"] = await db1.Resource.ConnectionStringExpression.GetValueAsync(default), + [$"ConnectionStrings:{db1.Resource.Name}"] = await db1.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken), }); hb1.AddSqlServerClient(db1.Resource.Name); using var host1 = hb1.Build(); - await host1.StartAsync(); + await host1.StartAsync(TestContext.Current.CancellationToken); await pipeline.ExecuteAsync(async token => { @@ -216,7 +216,7 @@ await pipeline.ExecuteAsync(async token => Assert.True(results.HasRows); }, cts.Token); - await app1.StopAsync(); + await app1.StopAsync(TestContext.Current.CancellationToken); await pipeline.ExecuteAsync(async token => { @@ -239,7 +239,7 @@ await pipeline.ExecuteAsync(async token => finally { // Stops the container, or the Volume/mount would still be in use - await app1.StopAsync(); + await app1.StopAsync(TestContext.Current.CancellationToken); } using var builder2 = TestDistributedApplicationBuilder.Create(o => { }, testOutputHelper); @@ -259,7 +259,7 @@ await pipeline.ExecuteAsync(async token => using (var app2 = builder2.Build()) { - await app2.StartAsync(); + await app2.StartAsync(TestContext.Current.CancellationToken); await app2.ResourceNotifications.WaitForResourceHealthyAsync(db2.Resource.Name, cts.Token); @@ -269,14 +269,14 @@ await pipeline.ExecuteAsync(async token => hb2.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{db2.Resource.Name}"] = await db2.Resource.ConnectionStringExpression.GetValueAsync(default), + [$"ConnectionStrings:{db2.Resource.Name}"] = await db2.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken), }); hb2.AddSqlServerClient(db2.Resource.Name); using (var host2 = hb2.Build()) { - await host2.StartAsync(); + await host2.StartAsync(TestContext.Current.CancellationToken); await pipeline.ExecuteAsync(async token => { @@ -303,7 +303,7 @@ await pipeline.ExecuteAsync(async token => finally { // Stops the container, or the Volume/mount would still be in use - await app2.StopAsync(); + await app2.StopAsync(TestContext.Current.CancellationToken); } } @@ -365,13 +365,13 @@ public async Task AddDatabaseCreatesDatabaseWithCustomScript() var hb = Host.CreateApplicationBuilder(); - hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(default); + hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); hb.AddSqlServerClient(newDb.Resource.Name); using var host = hb.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); await app.ResourceNotifications.WaitForResourceHealthyAsync(newDb.Resource.Name, cts.Token); @@ -418,7 +418,7 @@ public async Task AddDatabaseCreatesDatabaseWithSpecialNames() var hb = Host.CreateApplicationBuilder(); - hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(default); + hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); hb.AddSqlServerClient(newDb.Resource.Name); @@ -490,13 +490,13 @@ public async Task AddDatabaseCreatesDatabaseResiliently() var hb = Host.CreateApplicationBuilder(); - hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(default); + hb.Configuration[$"ConnectionStrings:{newDb.Resource.Name}"] = await newDb.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); hb.AddSqlServerClient(newDb.Resource.Name); using var host = hb.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); await app.ResourceNotifications.WaitForResourceHealthyAsync(sqlserver.Resource.Name, cts.Token); @@ -550,13 +550,13 @@ public async Task AddDatabaseCreatesMultipleDatabases() foreach (var db in dbs) { - hb.Configuration[$"ConnectionStrings:{db.Resource.Name}"] = await db.Resource.ConnectionStringExpression.GetValueAsync(default); + hb.Configuration[$"ConnectionStrings:{db.Resource.Name}"] = await db.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken); hb.AddKeyedSqlServerClient(db.Resource.Name); } using var host = hb.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); foreach (var db in dbs) { diff --git a/tests/Aspire.Hosting.Testing.Tests/ResourceLoggerForwarderServiceTests.cs b/tests/Aspire.Hosting.Testing.Tests/ResourceLoggerForwarderServiceTests.cs index 2e1084139c8..9dd55fe0987 100644 --- a/tests/Aspire.Hosting.Testing.Tests/ResourceLoggerForwarderServiceTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/ResourceLoggerForwarderServiceTests.cs @@ -18,7 +18,7 @@ public class ResourceLoggerForwarderServiceTests(ITestOutputHelper output) [Fact] public async Task BackgroundServiceIsRegisteredInServiceProvider() { - var appHost = await DistributedApplicationTestingBuilder.CreateAsync(); + var appHost = await DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken); Assert.Contains(appHost.Services, sd => sd.ServiceType == typeof(IHostedService) && sd.ImplementationType == typeof(ResourceLoggerForwarderService) @@ -67,7 +67,7 @@ public async Task ResourceLogsAreForwardedToHostLogging() subscribedTcs.TrySetResult(); } } - }); + }, TestContext.Current.CancellationToken); var expectedLogCountTcs = new TaskCompletionSource(); var expectedLogCount = 6; @@ -88,7 +88,7 @@ public async Task ResourceLogsAreForwardedToHostLogging() await resourceNotificationService.PublishUpdateAsync(myresource, snapshot => snapshot with { State = "Running" }); // Wait for the log stream to begin - await subscribedTcs.Task.WaitAsync(TimeSpan.FromSeconds(15)); + await subscribedTcs.Task.WaitAsync(TimeSpan.FromSeconds(15), TestContext.Current.CancellationToken); // Log messages to the resource fakeLoggerProvider.Collector.Clear(); @@ -102,7 +102,7 @@ public async Task ResourceLogsAreForwardedToHostLogging() resourceLogger.LogCritical("Test critical message"); // Wait for the 6 log messages or timeout - await expectedLogCountTcs.Task.WaitAsync(TimeSpan.FromSeconds(15)); + await expectedLogCountTcs.Task.WaitAsync(TimeSpan.FromSeconds(15), TestContext.Current.CancellationToken); // Complete the resource log stream and wait for it to end resourceLoggerService.Complete(myresource); diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs index 54f8f357f75..946e546d698 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs @@ -54,10 +54,10 @@ public async Task CanLoadFromDirectoryOutsideOfAppContextBaseDirectory() ?? throw new InvalidOperationException("Generated AppHost type not found."); TestResourceNames resourcesToSkip = ~TestResourceNames.redis; - var builder = await DistributedApplicationTestingBuilder.CreateAsync(appHostType, ["--skip-resources", resourcesToSkip.ToCSVString()]); + var builder = await DistributedApplicationTestingBuilder.CreateAsync(appHostType, ["--skip-resources", resourcesToSkip.ToCSVString()], TestContext.Current.CancellationToken); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Sanity check that the app is running as expected // Get an endpoint from a resource @@ -69,7 +69,7 @@ public async Task CanLoadFromDirectoryOutsideOfAppContextBaseDirectory() [Fact] public async Task ThrowsForAssemblyWithoutAnEntrypoint() { - var ioe = await Assert.ThrowsAsync(() => DistributedApplicationTestingBuilder.CreateAsync(typeof(Microsoft.Extensions.Logging.ConsoleLoggerExtensions))); + var ioe = await Assert.ThrowsAsync(() => DistributedApplicationTestingBuilder.CreateAsync(typeof(Microsoft.Extensions.Logging.ConsoleLoggerExtensions), TestContext.Current.CancellationToken)); Assert.Contains("does not have an entry point", ioe.Message); } @@ -88,13 +88,13 @@ public async Task CreateAsyncWithOptions(bool genericEntryPoint) }; var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync([], configureBuilder) - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), [], configureBuilder)); + ? DistributedApplicationTestingBuilder.CreateAsync([], configureBuilder, TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), [], configureBuilder, TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); Assert.Equal(testEnvironmentName, builder.Environment.EnvironmentName); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); var appModel = app.Services.GetRequiredService(); foreach (var resource in appModel.GetContainerResources()) @@ -109,14 +109,14 @@ public async Task CreateAsyncWithOptions(bool genericEntryPoint) [Fact] public async Task CanSetEnvironment() { - var builder = await DistributedApplicationTestingBuilder.CreateAsync(["--environment=Testing"]); + var builder = await DistributedApplicationTestingBuilder.CreateAsync(["--environment=Testing"], TestContext.Current.CancellationToken); Assert.Equal("Testing", builder.Environment.EnvironmentName); } [Fact] public async Task EnvironmentDefaultsToDevelopment() { - var builder = await DistributedApplicationTestingBuilder.CreateAsync(); + var builder = await DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken); Assert.Equal(Environments.Development, builder.Environment.EnvironmentName); } @@ -127,11 +127,11 @@ public async Task EnvironmentDefaultsToDevelopment() public async Task HasEndPoints(bool genericEntryPoint) { var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync() - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost))); + ? DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Get an endpoint from a resource var workerEndpoint = app.GetEndpoint("myworker1", "myendpoint1"); @@ -139,7 +139,7 @@ public async Task HasEndPoints(bool genericEntryPoint) Assert.True(workerEndpoint.Host.Length > 0); // Get a connection string - var connectionString = await app.GetConnectionStringAsync("cs"); + var connectionString = await app.GetConnectionStringAsync("cs", TestContext.Current.CancellationToken); Assert.NotNull(connectionString); Assert.True(connectionString.Length > 0); } @@ -151,11 +151,11 @@ public async Task HasEndPoints(bool genericEntryPoint) public async Task CanGetResources(bool genericEntryPoint) { var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync() - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost))); + ? DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Ensure that the resource which we added is present in the model. var appModel = app.Services.GetRequiredService(); @@ -169,20 +169,20 @@ public async Task CanGetResources(bool genericEntryPoint) public async Task HttpClientGetTest(bool genericEntryPoint) { var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync() - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost))); + ? DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Wait for the application to be ready - await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); + await app.WaitForTextAsync("Application started.", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts => { opts.TotalRequestTimeout.Timeout = s_appAliveCheckTimeout; }); - var result1 = await httpClient.GetFromJsonAsync("/weatherforecast"); + var result1 = await httpClient.GetFromJsonAsync("/weatherforecast", TestContext.Current.CancellationToken); Assert.NotNull(result1); Assert.True(result1.Length > 0); } @@ -194,10 +194,10 @@ public async Task HttpClientGetTest(bool genericEntryPoint) public async Task GetHttpClientBeforeStart(bool genericEntryPoint) { var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync() - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost))); + ? DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); Assert.Throws(() => app.CreateHttpClient("mywebapp1")); } @@ -223,25 +223,25 @@ public async Task ArgsPropagateToAppHostConfiguration(bool genericEntryPoint, bo IDistributedApplicationTestingBuilder builder; if (genericEntryPoint) { - builder = await DistributedApplicationTestingBuilder.CreateAsync(args, configureBuilder); + builder = await DistributedApplicationTestingBuilder.CreateAsync(args, configureBuilder, TestContext.Current.CancellationToken); } else { - builder = await DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), args, configureBuilder); + builder = await DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), args, configureBuilder, TestContext.Current.CancellationToken); } builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Wait for the application to be ready - await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); + await app.WaitForTextAsync("Application started.", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts => { opts.TotalRequestTimeout.Timeout = s_appAliveCheckTimeout; }); - var appHostArg = await httpClient.GetStringAsync("/get-app-host-arg"); + var appHostArg = await httpClient.GetStringAsync("/get-app-host-arg", TestContext.Current.CancellationToken); Assert.NotNull(appHostArg); Assert.Equal("42", appHostArg); } @@ -269,17 +269,17 @@ public async Task ArgsPropagateToAppHostConfigurationAdHocBuilder(bool directArg builder.AddProject("mywebapp1") .WithEnvironment("APP_HOST_ARG", builder.Configuration["APP_HOST_ARG"]) .WithEnvironment("LAUNCH_PROFILE_VAR_FROM_APP_HOST", builder.Configuration["LAUNCH_PROFILE_VAR_FROM_APP_HOST"]); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Wait for the application to be ready - await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); + await app.WaitForTextAsync("Application started.", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts => { opts.TotalRequestTimeout.Timeout = s_appAliveCheckTimeout; }); - var appHostArg = await httpClient.GetStringAsync("/get-app-host-arg"); + var appHostArg = await httpClient.GetStringAsync("/get-app-host-arg", TestContext.Current.CancellationToken); Assert.NotNull(appHostArg); Assert.Equal("42", appHostArg); } @@ -310,24 +310,24 @@ public async Task CanOverrideLaunchProfileViaArgs(string launchProfileName, bool configureBuilder = (dao, habs) => habs.Args = [arg]; } - var builder = await DistributedApplicationTestingBuilder.CreateAsync(args, configureBuilder); + var builder = await DistributedApplicationTestingBuilder.CreateAsync(args, configureBuilder, TestContext.Current.CancellationToken); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Wait for the application to be ready - await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); + await app.WaitForTextAsync("Application started.", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts => { opts.TotalRequestTimeout.Timeout = s_appAliveCheckTimeout; }); - var appHostArg = await httpClient.GetStringAsync("/get-launch-profile-var"); + var appHostArg = await httpClient.GetStringAsync("/get-launch-profile-var", TestContext.Current.CancellationToken); Assert.NotNull(appHostArg); Assert.Equal($"it-is-{launchProfileName}", appHostArg); // Check that, aside from the launch profile, the app host loaded environment settings from its launch profile - var appHostLaunchProfileVar = await httpClient.GetStringAsync("/get-launch-profile-var-from-app-host"); + var appHostLaunchProfileVar = await httpClient.GetStringAsync("/get-launch-profile-var-from-app-host", TestContext.Current.CancellationToken); Assert.NotNull(appHostLaunchProfileVar); Assert.Equal($"app-host-is-{launchProfileName}", appHostLaunchProfileVar); } @@ -362,22 +362,22 @@ public async Task CanOverrideLaunchProfileViaArgsAdHocBuilder(string launchProfi builder.WithTestAndResourceLogging(output); builder.AddProject("mywebapp1") .WithEnvironment("LAUNCH_PROFILE_VAR_FROM_APP_HOST", builder.Configuration["LAUNCH_PROFILE_VAR_FROM_APP_HOST"]); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); // Wait for the application to be ready - await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); + await app.WaitForTextAsync("Application started.", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts => { opts.TotalRequestTimeout.Timeout = s_appAliveCheckTimeout; }); - var appHostArg = await httpClient.GetStringAsync("/get-launch-profile-var"); + var appHostArg = await httpClient.GetStringAsync("/get-launch-profile-var", TestContext.Current.CancellationToken); Assert.NotNull(appHostArg); Assert.Equal($"it-is-{launchProfileName}", appHostArg); // Check that, aside from the launch profile, the app host loaded environment settings from its launch profile - var appHostLaunchProfileVar = await httpClient.GetStringAsync("/get-launch-profile-var-from-app-host"); + var appHostLaunchProfileVar = await httpClient.GetStringAsync("/get-launch-profile-var-from-app-host", TestContext.Current.CancellationToken); Assert.NotNull(appHostLaunchProfileVar); Assert.Equal($"app-host-is-{launchProfileName}", appHostLaunchProfileVar); } @@ -389,11 +389,11 @@ public async Task CanOverrideLaunchProfileViaArgsAdHocBuilder(string launchProfi public async Task SetsCorrectContentRoot(bool genericEntryPoint) { var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync() - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost))); + ? DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); var hostEnvironment = app.Services.GetRequiredService(); Assert.Contains("TestingAppHost1", hostEnvironment.ContentRootPath); } @@ -405,24 +405,24 @@ public async Task SetsCorrectContentRoot(bool genericEntryPoint) public async Task SelectsFirstLaunchProfile(bool genericEntryPoint) { var builder = await (genericEntryPoint - ? DistributedApplicationTestingBuilder.CreateAsync() - : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost))); + ? DistributedApplicationTestingBuilder.CreateAsync(TestContext.Current.CancellationToken) + : DistributedApplicationTestingBuilder.CreateAsync(typeof(Projects.TestingAppHost1_AppHost), TestContext.Current.CancellationToken)); builder.WithTestAndResourceLogging(output); - await using var app = await builder.BuildAsync(); - await app.StartAsync(); + await using var app = await builder.BuildAsync(TestContext.Current.CancellationToken); + await app.StartAsync(TestContext.Current.CancellationToken); var config = app.Services.GetRequiredService(); var profileName = config["DOTNET_LAUNCH_PROFILE"]; Assert.Equal("https", profileName); // Wait for the application to be ready - await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); + await app.WaitForTextAsync("Application started.", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); // Explicitly get the HTTPS endpoint - this is only available on the "https" launch profile. var httpClient = app.CreateHttpClientWithResilience("mywebapp1", "https", opts => { opts.TotalRequestTimeout.Timeout = s_appAliveCheckTimeout; }); - var result = await httpClient.GetFromJsonAsync("/weatherforecast"); + var result = await httpClient.GetFromJsonAsync("/weatherforecast", TestContext.Current.CancellationToken); Assert.NotNull(result); Assert.True(result.Length > 0); } @@ -461,17 +461,17 @@ public async Task CrashTests(bool genericEntryPoint, string crashArg) cts.CancelAfter(timeout); builder.WithTestAndResourceLogging(output); - using var app = await builder.BuildAsync().WaitAsync(cts.Token); + using var app = await builder.BuildAsync(TestContext.Current.CancellationToken).WaitAsync(cts.Token); cts.CancelAfter(timeout); if (crashArg == "after-build") { - var exception = await Assert.ThrowsAsync(() => app.StartAsync().WaitAsync(cts.Token)); + var exception = await Assert.ThrowsAsync(() => app.StartAsync( TestContext.Current.CancellationToken).WaitAsync(cts.Token)); Assert.Contains(crashArg, exception.Message); } else { - await app.StartAsync().WaitAsync(cts.Token); + await app.StartAsync(TestContext.Current.CancellationToken).WaitAsync(cts.Token); } cts.CancelAfter(timeout); @@ -493,7 +493,7 @@ public async Task StartAsyncAbandonedAfterCrash() using var builder = await DistributedApplicationTestingBuilder.CreateAsync(["--add-unknown-container"], cts.Token).WaitAsync(cts.Token); cts.CancelAfter(timeout); await using var app = await builder.BuildAsync(cts.Token).WaitAsync(cts.Token); - await app.StartAsync().WaitAsync(TimeSpan.FromSeconds(10)); + await app.StartAsync(TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); Assert.Fail(); } catch (Exception ex) @@ -530,7 +530,7 @@ public async Task StartAsyncAbandonedAfterHang() { app = await builder.BuildAsync(cts.Token).WaitAsync(cts.Token); - await app.StartAsync().WaitAsync(TimeSpan.FromSeconds(10)); + await app.StartAsync(TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken); } finally { diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs index 71ddbb3dedf..238d325bee4 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs @@ -24,12 +24,12 @@ public async Task CrashTests(string crashArg) if (crashArg is "before-build" or "after-build") { - var exception = await Assert.ThrowsAsync(() => factory.StartAsync().WaitAsync(cts.Token)); + var exception = await Assert.ThrowsAsync(() => factory.StartAsync(TestContext.Current.CancellationToken).WaitAsync(cts.Token)); Assert.Contains(crashArg, exception.Message); } else { - await factory.StartAsync().WaitAsync(cts.Token); + await factory.StartAsync(TestContext.Current.CancellationToken).WaitAsync(cts.Token); } await factory.DisposeAsync().AsTask().WaitAsync(cts.Token); diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs index 58006861e9c..a1199816b0c 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryTests.cs @@ -30,8 +30,8 @@ public void HasEndPoints() public async Task CanGetConnectionStringFromAddConnectionString() { // Get a connection string from a resource - var connectionString = await _app.GetConnectionStringAsync("cs"); - var connectionString2 = await _app.GetConnectionStringAsync("cs2"); + var connectionString = await _app.GetConnectionStringAsync("cs", TestContext.Current.CancellationToken); + var connectionString2 = await _app.GetConnectionStringAsync("cs2", TestContext.Current.CancellationToken); Assert.Equal("testconnection", connectionString); Assert.Equal("Value=this is a value", connectionString2); } @@ -49,11 +49,11 @@ public void CanGetResources() public async Task HttpClientGetTest() { // Wait for the application to be ready - await _app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1)); + await _app.WaitForTextAsync("Application started.", "mywebapp1", TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var httpClient = _app.CreateHttpClientWithResilience("mywebapp1"); - var result1 = await httpClient.GetFromJsonAsync("/weatherforecast"); + var result1 = await httpClient.GetFromJsonAsync("/weatherforecast", TestContext.Current.CancellationToken); Assert.NotNull(result1); Assert.True(result1.Length > 0); } @@ -76,11 +76,11 @@ public async Task SelectsFirstLaunchProfile() Assert.Equal("https", profileName); // Wait for resource to start. - await _app.ResourceNotifications.WaitForResourceAsync("mywebapp1").WaitAsync(TimeSpan.FromSeconds(60)); + await _app.ResourceNotifications.WaitForResourceAsync("mywebapp1", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromSeconds(60), TestContext.Current.CancellationToken); // Explicitly get the HTTPS endpoint - this is only available on the "https" launch profile. var httpClient = _app.CreateHttpClientWithResilience("mywebapp1", "https"); - var result = await httpClient.GetFromJsonAsync("/weatherforecast"); + var result = await httpClient.GetFromJsonAsync("/weatherforecast", TestContext.Current.CancellationToken); Assert.NotNull(result); Assert.True(result.Length > 0); } diff --git a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj index a2d06c1735a..e3573fc9663 100644 --- a/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj +++ b/tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj @@ -1,11 +1,11 @@ - + $(DefaultTargetFramework) - $(NoWarn);CS8002 + $(NoWarn);CS8002;xUnit1051 false diff --git a/tests/Aspire.Hosting.Valkey.Tests/AddValkeyTests.cs b/tests/Aspire.Hosting.Valkey.Tests/AddValkeyTests.cs index 1d3e70cc9d9..e291e5c3bf8 100644 --- a/tests/Aspire.Hosting.Valkey.Tests/AddValkeyTests.cs +++ b/tests/Aspire.Hosting.Valkey.Tests/AddValkeyTests.cs @@ -80,7 +80,7 @@ public async Task ValkeyCreatesConnectionStringWithDefaultPassword() var appModel = app.Services.GetRequiredService(); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("{myValkey.bindings.tcp.host}:{myValkey.bindings.tcp.port},password={myValkey-password.value}", connectionStringResource.ConnectionStringExpression.ValueExpression); Assert.StartsWith("localhost:2000", connectionString); } @@ -336,7 +336,7 @@ public async Task AddValkeyContainerWithPasswordAnnotationMetadata() var containerResource = Assert.Single(appModel.Resources.OfType()); var connectionStringResource = Assert.Single(appModel.Resources.OfType()); - var connectionString = await connectionStringResource.GetConnectionStringAsync(default); + var connectionString = await connectionStringResource.GetConnectionStringAsync(TestContext.Current.CancellationToken); Assert.Equal("{myValkey.bindings.tcp.host}:{myValkey.bindings.tcp.port},password={pass.value}", connectionStringResource.ConnectionStringExpression.ValueExpression); Assert.StartsWith($"localhost:5001,password={password}", connectionString); } diff --git a/tests/Aspire.Hosting.Valkey.Tests/ValkeyFunctionalTests.cs b/tests/Aspire.Hosting.Valkey.Tests/ValkeyFunctionalTests.cs index 8b9154ac581..458dbdfea09 100644 --- a/tests/Aspire.Hosting.Valkey.Tests/ValkeyFunctionalTests.cs +++ b/tests/Aspire.Hosting.Valkey.Tests/ValkeyFunctionalTests.cs @@ -27,22 +27,22 @@ public async Task VerifyValkeyResource() using var app = builder.Build(); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); var hb = Host.CreateApplicationBuilder(); hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{valkey.Resource.Name}"] = await valkey.Resource.ConnectionStringExpression.GetValueAsync(default) + [$"ConnectionStrings:{valkey.Resource.Name}"] = await valkey.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken) }); hb.AddRedisClient(valkey.Resource.Name); using var host = hb.Build(); - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForHealthyAsync(valkey).WaitAsync(TestConstants.LongTimeoutTimeSpan); + await app.WaitForHealthyAsync(valkey, TestContext.Current.CancellationToken).WaitAsync(TestConstants.LongTimeoutTimeSpan, TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -87,7 +87,7 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) using (var app = builder1.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); try { var hb = Host.CreateApplicationBuilder(); @@ -95,16 +95,16 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) // BGSAVE is only available in admin mode, enable it for this instance hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{valkey1.Resource.Name}"] = $"{await valkey1.Resource.ConnectionStringExpression.GetValueAsync(default)},allowAdmin=true" + [$"ConnectionStrings:{valkey1.Resource.Name}"] = $"{await valkey1.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken)},allowAdmin=true" }); hb.AddRedisClient(valkey1.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForHealthyAsync(valkey1).WaitAsync(TestConstants.LongTimeoutTimeSpan); + await app.WaitForHealthyAsync(valkey1, TestContext.Current.CancellationToken).WaitAsync(TestConstants.LongTimeoutTimeSpan, TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -121,7 +121,7 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) finally { // Stops the container, or the Volume/mount would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } @@ -139,23 +139,23 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) using (var app = builder2.Build()) { - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); try { var hb = Host.CreateApplicationBuilder(); hb.Configuration.AddInMemoryCollection(new Dictionary { - [$"ConnectionStrings:{valkey2.Resource.Name}"] = await valkey2.Resource.ConnectionStringExpression.GetValueAsync(default) + [$"ConnectionStrings:{valkey2.Resource.Name}"] = await valkey2.Resource.ConnectionStringExpression.GetValueAsync(TestContext.Current.CancellationToken) }); hb.AddRedisClient(valkey2.Resource.Name); using (var host = hb.Build()) { - await host.StartAsync(); + await host.StartAsync(TestContext.Current.CancellationToken); - await app.WaitForHealthyAsync(valkey2).WaitAsync(TestConstants.LongTimeoutTimeSpan); + await app.WaitForHealthyAsync(valkey2, TestContext.Current.CancellationToken).WaitAsync(TestConstants.LongTimeoutTimeSpan, TestContext.Current.CancellationToken); var redisClient = host.Services.GetRequiredService(); @@ -169,7 +169,7 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume) finally { // Stops the container, or the Volume/mount would still be in use - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } } @@ -229,6 +229,6 @@ public async Task VerifyWaitForOnValkeyBlocksDependentResources() await pendingStart; - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } } diff --git a/tests/Aspire.Milvus.Client.Tests/AspireMilvusExtensionTests.cs b/tests/Aspire.Milvus.Client.Tests/AspireMilvusExtensionTests.cs index 3f5c21b272b..b435e09f009 100644 --- a/tests/Aspire.Milvus.Client.Tests/AspireMilvusExtensionTests.cs +++ b/tests/Aspire.Milvus.Client.Tests/AspireMilvusExtensionTests.cs @@ -134,7 +134,7 @@ public async Task AddMilvusClient_HealthCheckShouldBeRegisteredByDefault(bool us var healthCheckService = host.Services.GetRequiredService(); - var healthCheckReport = await healthCheckService.CheckHealthAsync(); + var healthCheckReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken); var healthCheckName = useKeyed ? $"Milvus_{DefaultKeyName}" : "Milvus"; diff --git a/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs b/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs index be56e088f3a..adfe481481e 100644 --- a/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs +++ b/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs @@ -131,7 +131,7 @@ public async Task AddMongoDBDataSource_HealthCheckShouldBeRegisteredWhenEnabled( var healthCheckService = host.Services.GetRequiredService(); - var healthCheckReport = await healthCheckService.CheckHealthAsync(); + var healthCheckReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken); var healthCheckName = "MongoDB.Driver"; @@ -175,7 +175,7 @@ public async Task AddKeyedMongoDBDataSource_HealthCheckShouldBeRegisteredWhenEna var healthCheckService = host.Services.GetRequiredService(); - var healthCheckReport = await healthCheckService.CheckHealthAsync(); + var healthCheckReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken); var healthCheckName = $"MongoDB.Driver_{key}"; diff --git a/tests/Aspire.NATS.Net.Tests/AspireNatsClientExtensionsTests.cs b/tests/Aspire.NATS.Net.Tests/AspireNatsClientExtensionsTests.cs index b478d7521ec..787c14f5061 100644 --- a/tests/Aspire.NATS.Net.Tests/AspireNatsClientExtensionsTests.cs +++ b/tests/Aspire.NATS.Net.Tests/AspireNatsClientExtensionsTests.cs @@ -169,7 +169,7 @@ public async Task AddNatsClient_HealthCheckShouldBeRegisteredByDefault(bool useK var healthCheckService = host.Services.GetRequiredService(); - var healthCheckReport = await healthCheckService.CheckHealthAsync(); + var healthCheckReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken); var healthCheckName = useKeyed ? $"NATS_{key}" : "NATS"; diff --git a/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderChatClientExtensionsTests.cs b/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderChatClientExtensionsTests.cs index 3f0e6080dfc..5f81c0be0d8 100644 --- a/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderChatClientExtensionsTests.cs +++ b/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderChatClientExtensionsTests.cs @@ -217,7 +217,7 @@ public async Task CanConfigurePipelineAsync(bool useKeyed) host.Services.GetRequiredKeyedService("openai_chatclient") : host.Services.GetRequiredService(); - var completion = await client.GetResponseAsync("Whatever"); + var completion = await client.GetResponseAsync("Whatever", cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("Hello from middleware", completion.Text); } @@ -251,7 +251,7 @@ public async Task LogsCorrectly(bool useKeyed, bool disableOpenTelemetry) host.Services.GetRequiredService(); var loggerFactory = (TestLoggerFactory)host.Services.GetRequiredService(); - var completion = await client.GetResponseAsync("Whatever"); + var completion = await client.GetResponseAsync("Whatever", cancellationToken: TestContext.Current.CancellationToken); Assert.Equal("Hello from middleware", completion.Text); const string category = "Microsoft.Extensions.AI.OpenTelemetryChatClient"; diff --git a/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs b/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs index d5a243e67e8..e6307f908e5 100644 --- a/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs +++ b/tests/Aspire.OpenAI.Tests/AspireOpenAIClientBuilderEmbeddingGeneratorExtensionsTests.cs @@ -217,7 +217,7 @@ public async Task CanConfigurePipelineAsync(bool useKeyed) host.Services.GetRequiredKeyedService>>("openai_embeddinggenerator") : host.Services.GetRequiredService>>(); - var vector = await generator.GenerateEmbeddingVectorAsync("Hello"); + var vector = await generator.GenerateEmbeddingVectorAsync("Hello", cancellationToken: TestContext.Current.CancellationToken); Assert.Equal(1.23f, vector.ToArray().Single()); } @@ -251,7 +251,7 @@ public async Task LogsCorrectly(bool useKeyed, bool disableOpenTelemetry) host.Services.GetRequiredService>>(); var loggerFactory = (TestLoggerFactory)host.Services.GetRequiredService(); - var vector = await generator.GenerateEmbeddingVectorAsync("Hello"); + var vector = await generator.GenerateEmbeddingVectorAsync("Hello", cancellationToken: TestContext.Current.CancellationToken); Assert.Equal(1.23f, vector.ToArray().Single()); const string category = "Microsoft.Extensions.AI.OpenTelemetryEmbeddingGenerator"; diff --git a/tests/Aspire.Playground.Tests/AppHostTests.cs b/tests/Aspire.Playground.Tests/AppHostTests.cs index 9d55bece4ed..b22d4df54a9 100644 --- a/tests/Aspire.Playground.Tests/AppHostTests.cs +++ b/tests/Aspire.Playground.Tests/AppHostTests.cs @@ -37,9 +37,9 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints) var resourceEndpoints = testEndpoints.ResourceEndpoints!; var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostType, _testOutput); var projects = appHost.Resources.OfType(); - await using var app = await appHost.BuildAsync(); + await using var app = await appHost.BuildAsync(TestContext.Current.CancellationToken); - await app.StartAsync(); + await app.StartAsync(TestContext.Current.CancellationToken); if (testEndpoints.WaitForTexts != null) { @@ -47,7 +47,7 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints) var tasks = testEndpoints.WaitForTexts.Select(x => app.WaitForTextAsync(log => new Regex(x.Pattern).IsMatch(log), x.ResourceName)).ToArray(); try { - await Task.WhenAll(tasks).WaitAsync(TimeSpan.FromMinutes(5)); + await Task.WhenAll(tasks).WaitAsync(TimeSpan.FromMinutes(5), TestContext.Current.CancellationToken); } catch (TimeoutException te) { @@ -67,7 +67,7 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints) { var applicationModel = app.Services.GetRequiredService(); - await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(5)); + await app.WaitForResources( cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(5), TestContext.Current.CancellationToken); if (testEndpoints.WaitForResources?.Count > 0) { @@ -76,7 +76,7 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints) foreach (var (ResourceName, TargetState) in testEndpoints.WaitForResources) { _testOutput.WriteLine($"Waiting for resource '{ResourceName}' to reach state '{TargetState}' in app '{appHost.AppHostAssembly}'"); - await app.WaitForResource(ResourceName, TargetState).WaitAsync(TimeSpan.FromMinutes(5)); + await app.WaitForResource(ResourceName, TargetState, TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(5), TestContext.Current.CancellationToken); } } } @@ -99,7 +99,7 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints) _testOutput.WriteLine($"Calling endpoint '{client.BaseAddress}{path.TrimStart('/')} for resource '{resource}' in app '{appHost.AppHostAssembly}'"); try { - response = await client.GetAsync(path); + response = await client.GetAsync(path, TestContext.Current.CancellationToken); } catch (TimeoutRejectedException tre) { @@ -111,7 +111,7 @@ public async Task TestEndpointsReturnOk(TestEndpoints testEndpoints) } app.EnsureNoErrorsLogged(); - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } public static HttpClient CreateHttpClientWithResilience(DistributedApplication app, string resource) diff --git a/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj b/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj index d07a3033a95..d8e17c6389e 100644 --- a/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj +++ b/tests/Aspire.Playground.Tests/Aspire.Playground.Tests.csproj @@ -22,15 +22,6 @@ xunit.runner.json - - - $(NoWarn);xUnit1051 diff --git a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs index 62742048d2c..3216224214d 100644 --- a/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs +++ b/tests/Aspire.Playground.Tests/ProjectSpecificTests.cs @@ -17,16 +17,16 @@ public class ProjectSpecificTests(ITestOutputHelper _testOutput) public async Task WithDockerfileTest() { var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.WithDockerfile_AppHost), _testOutput); - await using var app = await appHost.BuildAsync(); + await using var app = await appHost.BuildAsync(TestContext.Current.CancellationToken); - await app.StartAsync(); - await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2)); + await app.StartAsync(TestContext.Current.CancellationToken); + await app.WaitForResources(cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(2), TestContext.Current.CancellationToken); - await app.WaitForTextAsync($"I'm Batman. - Batman") - .WaitAsync(TimeSpan.FromMinutes(3)); + await app.WaitForTextAsync($"I'm Batman. - Batman", cancellationToken: TestContext.Current.CancellationToken) + .WaitAsync(TimeSpan.FromMinutes(3), TestContext.Current.CancellationToken); app.EnsureNoErrorsLogged(); - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } [Fact] @@ -34,13 +34,13 @@ await app.WaitForTextAsync($"I'm Batman. - Batman") public async Task KafkaTest() { var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.KafkaBasic_AppHost), _testOutput); - await using var app = await appHost.BuildAsync(); + await using var app = await appHost.BuildAsync(TestContext.Current.CancellationToken); - await app.StartAsync(); - await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2)); + await app.StartAsync(TestContext.Current.CancellationToken); + await app.WaitForResources(cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(2), TestContext.Current.CancellationToken); // Wait for the producer to start sending messages - await app.WaitForTextAsync("Hello, World!").WaitAsync(TimeSpan.FromMinutes(5)); + await app.WaitForTextAsync("Hello, World!", cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(5), TestContext.Current.CancellationToken); // Wait for the consumer to receive some messages await WaitForAllTextAsync(app, @@ -51,7 +51,7 @@ await WaitForAllTextAsync(app, timeoutSecs: 120); app.EnsureNoErrorsLogged(); - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } [Fact] @@ -60,10 +60,10 @@ await WaitForAllTextAsync(app, public async Task AzureFunctionsTest() { var appHost = await DistributedApplicationTestFactory.CreateAsync(typeof(Projects.AzureFunctionsEndToEnd_AppHost), _testOutput); - await using var app = await appHost.BuildAsync(); + await using var app = await appHost.BuildAsync(TestContext.Current.CancellationToken); - await app.StartAsync(); - await app.WaitForResources().WaitAsync(TimeSpan.FromMinutes(2)); + await app.StartAsync(TestContext.Current.CancellationToken); + await app.WaitForResources(cancellationToken: TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromMinutes(2), TestContext.Current.CancellationToken); // Wait for the 'Job host started' message as an indication // that the Functions host has initialized correctly @@ -75,7 +75,7 @@ await WaitForAllTextAsync(app, timeoutSecs: 160); // Assert that HTTP triggers work correctly - await AppHostTests.CreateHttpClientWithResilience(app, "funcapp").GetAsync("/api/injected-resources"); + await AppHostTests.CreateHttpClientWithResilience(app, "funcapp").GetAsync("/api/injected-resources", TestContext.Current.CancellationToken); await WaitForAllTextAsync(app, [ "Executed 'Functions.injected-resources'" @@ -85,7 +85,7 @@ await WaitForAllTextAsync(app, using var apiServiceClient = AppHostTests.CreateHttpClientWithResilience(app, "apiservice"); // Assert that Azure Storage Queue triggers work correctly - await apiServiceClient.GetAsync("/publish/asq"); + await apiServiceClient.GetAsync("/publish/asq", TestContext.Current.CancellationToken); await WaitForAllTextAsync(app, [ "Executed 'Functions.MyAzureQueueTrigger'" @@ -94,7 +94,7 @@ await WaitForAllTextAsync(app, timeoutSecs: 160); // Assert that Azure Storage Blob triggers work correctly - await apiServiceClient.GetAsync("/publish/blob"); + await apiServiceClient.GetAsync("/publish/blob", TestContext.Current.CancellationToken); await WaitForAllTextAsync(app, [ "Executed 'Functions.MyAzureBlobTrigger'" @@ -103,7 +103,7 @@ await WaitForAllTextAsync(app, timeoutSecs: 160); // Assert that EventHubs triggers work correctly - await apiServiceClient.GetAsync("/publish/eventhubs"); + await apiServiceClient.GetAsync("/publish/eventhubs", TestContext.Current.CancellationToken); await WaitForAllTextAsync(app, [ "Executed 'Functions.MyEventHubTrigger'" @@ -113,7 +113,7 @@ await WaitForAllTextAsync(app, #if !SKIP_UNSTABLE_EMULATORS // https://github.com/dotnet/aspire/issues/7066 // Assert that ServiceBus triggers work correctly - await apiServiceClient.GetAsync("/publish/asb"); + await apiServiceClient.GetAsync("/publish/asb", TestContext.Current.CancellationToken); await WaitForAllTextAsync(app, [ "Executed 'Functions.MyServiceBusTrigger'" @@ -126,7 +126,7 @@ await WaitForAllTextAsync(app, // resource that happens after the Functions host has been built. The error log shows up after the Functions // worker extension has been built and before the host has launched. // app.EnsureNoErrorsLogged(); - await app.StopAsync(); + await app.StopAsync(TestContext.Current.CancellationToken); } internal static Task WaitForAllTextAsync(DistributedApplication app, IEnumerable logTexts, string? resourceName = null, int timeoutSecs = -1) diff --git a/tests/Aspire.Qdrant.Client.Tests/AspireQdrantClientExtensionsTest.cs b/tests/Aspire.Qdrant.Client.Tests/AspireQdrantClientExtensionsTest.cs index eee1670c05a..915c27479b1 100644 --- a/tests/Aspire.Qdrant.Client.Tests/AspireQdrantClientExtensionsTest.cs +++ b/tests/Aspire.Qdrant.Client.Tests/AspireQdrantClientExtensionsTest.cs @@ -48,7 +48,7 @@ public async Task AddQdrantClient_HealthCheckShouldBeRegisteredWhenEnabled(bool var healthCheckService = host.Services.GetRequiredService(); - var healthCheckReport = await healthCheckService.CheckHealthAsync(); + var healthCheckReport = await healthCheckService.CheckHealthAsync(TestContext.Current.CancellationToken); var healthCheckName = useKeyed ? $"Qdrant.Client_{key}" : "Qdrant.Client"; diff --git a/tests/Aspire.RabbitMQ.Client.Tests/AspireRabbitMQLoggingTests.cs b/tests/Aspire.RabbitMQ.Client.Tests/AspireRabbitMQLoggingTests.cs index 90aa3faccae..2c8e8f5f64a 100644 --- a/tests/Aspire.RabbitMQ.Client.Tests/AspireRabbitMQLoggingTests.cs +++ b/tests/Aspire.RabbitMQ.Client.Tests/AspireRabbitMQLoggingTests.cs @@ -37,7 +37,7 @@ public async Task EndToEndLoggingTest() await using var rabbitMqContainer = new RabbitMqBuilder() .WithImage($"{ComponentTestConstants.AspireTestContainerRegistry}/{RabbitMQContainerImageTags.Image}:{RabbitMQContainerImageTags.Tag}") .Build(); - await rabbitMqContainer.StartAsync(); + await rabbitMqContainer.StartAsync(TestContext.Current.CancellationToken); var builder = Host.CreateEmptyApplicationBuilder(null); builder.Configuration.AddInMemoryCollection([ @@ -62,10 +62,10 @@ public async Task EndToEndLoggingTest() using var host = builder.Build(); using var connection = host.Services.GetRequiredService(); - await rabbitMqContainer.StopAsync(); + await rabbitMqContainer.StopAsync(TestContext.Current.CancellationToken); await rabbitMqContainer.DisposeAsync(); - await tsc.Task.WaitAsync(TimeSpan.FromMinutes(1)); + await tsc.Task.WaitAsync(TimeSpan.FromMinutes(1), TestContext.Current.CancellationToken); var logs = logger.Logs.ToArray(); Assert.True(logs.Length >= 2, "Should be at least 2 logs written."); diff --git a/tests/Aspire.StackExchange.Redis.Tests/AspireRedisExtensionsTests.cs b/tests/Aspire.StackExchange.Redis.Tests/AspireRedisExtensionsTests.cs index 96ff3463148..370421f5686 100644 --- a/tests/Aspire.StackExchange.Redis.Tests/AspireRedisExtensionsTests.cs +++ b/tests/Aspire.StackExchange.Redis.Tests/AspireRedisExtensionsTests.cs @@ -376,7 +376,7 @@ public async Task CanAddMultipleKeyedCachingServices() Assert.Empty(connection3.GetServers().Single().Keys()); // set a value in the output cache and ensure it was added to the redis3 server - await outputCache.SetAsync("outputKey", [1, 2, 3, 4], tags: null, validFor: TimeSpan.MaxValue, cancellationToken: default); + await outputCache.SetAsync("outputKey", [1, 2, 3, 4], tags: null, validFor: TimeSpan.MaxValue, cancellationToken: TestContext.Current.CancellationToken); Assert.Empty(connection1.GetServers().Single().Keys()); Assert.Single(connection2.GetServers().Single().Keys()); diff --git a/tests/Aspire.Templates.Tests/AppHostTemplateTests.cs b/tests/Aspire.Templates.Tests/AppHostTemplateTests.cs index dab50938b6a..8d9f334b8ab 100644 --- a/tests/Aspire.Templates.Tests/AppHostTemplateTests.cs +++ b/tests/Aspire.Templates.Tests/AppHostTemplateTests.cs @@ -32,7 +32,7 @@ public async Task EnsureProjectsReferencing8_1_0AppHostWithNewerWorkloadCanBuild File.WriteAllText(projectPath, newContents); // Ensure project builds successfully - await project.BuildAsync(workingDirectory: project.RootDir); + await project.BuildAsync(workingDirectory: project.RootDir, token: TestContext.Current.CancellationToken); } [GeneratedRegex(@"(PackageReference\s.*""Aspire\.Hosting\.AppHost.*Version=)""[^""]+""")] diff --git a/tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj b/tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj index 9fdc76892f8..c81fe3a4199 100644 --- a/tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj +++ b/tests/Aspire.Templates.Tests/Aspire.Templates.Tests.csproj @@ -16,15 +16,6 @@ true Aspire.Templates.Tests - - $(NoWarn);xUnit1051 - true diff --git a/tests/Aspire.Templates.Tests/BuildAndRunTemplateTests.cs b/tests/Aspire.Templates.Tests/BuildAndRunTemplateTests.cs index 53148b30d23..9036274e689 100644 --- a/tests/Aspire.Templates.Tests/BuildAndRunTemplateTests.cs +++ b/tests/Aspire.Templates.Tests/BuildAndRunTemplateTests.cs @@ -34,8 +34,8 @@ public async Task BuildAndRunAspireTemplate(string config) string id = GetNewProjectId(prefix: $"aspire_{config}"); await using var project = await AspireProject.CreateNewTemplateProjectAsync(id, "aspire", _testOutput, buildEnvironment: BuildEnvironment.ForDefaultFramework); - await project.BuildAsync(extraBuildArgs: [$"-c {config}"]); - await project.StartAppHostAsync(extraArgs: [$"-c {config}"]); + await project.BuildAsync(extraBuildArgs: [$"-c {config}"], TestContext.Current.CancellationToken); + await project.StartAppHostAsync(extraArgs: [$"-c {config}"], token: TestContext.Current.CancellationToken); if (PlaywrightProvider.HasPlaywrightSupport) { @@ -55,9 +55,9 @@ public async Task BuildAndRunAspireTemplateWithCentralPackageManagement() CreateCPMFile(project, version); - await project.BuildAsync(); - await project.StartAppHostAsync(); - await project.StopAppHostAsync(); + await project.BuildAsync(token: TestContext.Current.CancellationToken); + await project.StartAppHostAsync(token: TestContext.Current.CancellationToken); + await project.StopAppHostAsync(TestContext.Current.CancellationToken); static string ExtractAndRemoveVersionFromPackageReference(AspireProject project) { @@ -124,7 +124,7 @@ public async Task ProjectWithNoHTTPSRequiresExplicitOverrideWithEnvironmentVaria buildEnvironment: testSpecificBuildEnvironment, extraArgs: "--no-https"); - await project.BuildAsync(); + await project.BuildAsync(token: TestContext.Current.CancellationToken); using var buildCmd = new DotNetCommand(_testOutput, buildEnv: testSpecificBuildEnvironment, label: "first-run") .WithWorkingDirectory(project.AppHostProjectDirectory); @@ -134,7 +134,7 @@ public async Task ProjectWithNoHTTPSRequiresExplicitOverrideWithEnvironmentVaria // Run with the environment variable set testSpecificBuildEnvironment.EnvVars[KnownConfigNames.AllowUnsecuredTransport] = "true"; - await project.StartAppHostAsync(); + await project.StartAppHostAsync(token: TestContext.Current.CancellationToken); if (PlaywrightProvider.HasPlaywrightSupport) { @@ -154,7 +154,7 @@ public async Task CreateAndModifyAspireAppHostTemplate(string version) ModifyProjectFile(project, version); - await project.BuildAsync(workingDirectory: project.RootDir); + await project.BuildAsync(workingDirectory: project.RootDir, token: TestContext.Current.CancellationToken); static void ModifyProjectFile(AspireProject project, string version) { diff --git a/tests/Aspire.Templates.Tests/NewUpAndBuildStandaloneTemplateTests.cs b/tests/Aspire.Templates.Tests/NewUpAndBuildStandaloneTemplateTests.cs index a47248183ff..ea72f104b99 100644 --- a/tests/Aspire.Templates.Tests/NewUpAndBuildStandaloneTemplateTests.cs +++ b/tests/Aspire.Templates.Tests/NewUpAndBuildStandaloneTemplateTests.cs @@ -34,7 +34,7 @@ public async Task CanNewAndBuild(string templateName, string extraArgs, TestSdk Assert.True(error is null, $"Expected to throw an exception with message: {error}"); - await project.BuildAsync(extraBuildArgs: [$"-c Debug"]); + await project.BuildAsync(extraBuildArgs: [$"-c Debug"], token: TestContext.Current.CancellationToken); } catch (ToolCommandException tce) when (error is not null) { diff --git a/tests/Aspire.Templates.Tests/NewUpAndBuildSupportProjectTemplatesTests.cs b/tests/Aspire.Templates.Tests/NewUpAndBuildSupportProjectTemplatesTests.cs index efc5e16c829..0d2854146bb 100644 --- a/tests/Aspire.Templates.Tests/NewUpAndBuildSupportProjectTemplatesTests.cs +++ b/tests/Aspire.Templates.Tests/NewUpAndBuildSupportProjectTemplatesTests.cs @@ -57,7 +57,7 @@ public async Task CanNewAndBuild(string templateName, string extraTestCreationAr extraArgs: extraTestCreationArgs, overrideRootDir: topLevelDir); - await project.BuildAsync(extraBuildArgs: [$"-c {config}"], workingDirectory: testProjectDir); + await project.BuildAsync(extraBuildArgs: [$"-c {config}"], workingDirectory: testProjectDir, token: TestContext.Current.CancellationToken); } catch (ToolCommandException tce) when (error is not null) { diff --git a/tests/Aspire.Templates.Tests/PerTestFrameworkTemplatesTests.cs b/tests/Aspire.Templates.Tests/PerTestFrameworkTemplatesTests.cs index b0b9b6719b4..a9f0366cce6 100644 --- a/tests/Aspire.Templates.Tests/PerTestFrameworkTemplatesTests.cs +++ b/tests/Aspire.Templates.Tests/PerTestFrameworkTemplatesTests.cs @@ -31,7 +31,7 @@ public async Task TemplatesForIndividualTestFrameworks(string prefix) _testOutput, buildEnvironment: BuildEnvironment.ForDefaultFramework); - await project.BuildAsync(extraBuildArgs: [$"-c {config}"]); + await project.BuildAsync(extraBuildArgs: [$"-c {config}"], token: TestContext.Current.CancellationToken); if (PlaywrightProvider.HasPlaywrightSupport && RequiresSSLCertificateAttribute.IsSupported) { await using (var context = await CreateNewBrowserContextAsync()) diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index beb44b89dcd..2835d575ce5 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -33,7 +33,7 @@ CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member' CS1712: Type parameter 'type_parameter' has no matching typeparam tag in the XML comment on 'type_or_member' (but other type parameters do) --> - $(NoWarn);1573;1591;1712 + $(NoWarn);1573;1591;1712; diff --git a/tests/Microsoft.Extensions.ServiceDiscovery.Tests/PassThroughServiceEndpointResolverTests.cs b/tests/Microsoft.Extensions.ServiceDiscovery.Tests/PassThroughServiceEndpointResolverTests.cs index f8cc2f282e1..e91203544bf 100644 --- a/tests/Microsoft.Extensions.ServiceDiscovery.Tests/PassThroughServiceEndpointResolverTests.cs +++ b/tests/Microsoft.Extensions.ServiceDiscovery.Tests/PassThroughServiceEndpointResolverTests.cs @@ -124,7 +124,7 @@ public async Task ResolveServiceEndpoint_Fallback_NoScheme() .BuildServiceProvider(); var resolver = services.GetRequiredService(); - var result = await resolver.GetEndpointsAsync("catalog", default); + var result = await resolver.GetEndpointsAsync("catalog", TestContext.Current.CancellationToken); Assert.Equal(new DnsEndPoint("catalog", 0), result.Endpoints[0].EndPoint); } } diff --git a/tests/Microsoft.Extensions.ServiceDiscovery.Tests/ServiceEndpointResolverTests.cs b/tests/Microsoft.Extensions.ServiceDiscovery.Tests/ServiceEndpointResolverTests.cs index 0e08c07271e..334ce5102ce 100644 --- a/tests/Microsoft.Extensions.ServiceDiscovery.Tests/ServiceEndpointResolverTests.cs +++ b/tests/Microsoft.Extensions.ServiceDiscovery.Tests/ServiceEndpointResolverTests.cs @@ -39,7 +39,7 @@ public async Task ServiceEndpointResolver_NoProvidersConfigured_Throws() var watcher = new ServiceEndpointWatcher([], NullLogger.Instance, "foo", TimeProvider.System, Options.Options.Create(new ServiceDiscoveryOptions())); var exception = Assert.Throws(watcher.Start); Assert.Equal("No service endpoint providers are configured.", exception.Message); - exception = await Assert.ThrowsAsync(async () => await watcher.GetEndpointsAsync()); + exception = await Assert.ThrowsAsync(async () => await watcher.GetEndpointsAsync(TestContext.Current.CancellationToken)); Assert.Equal("No service endpoint providers are configured.", exception.Message); } @@ -60,7 +60,7 @@ public async Task AddServiceDiscovery_NoProviders_Throws() serviceCollection.AddHttpClient("foo", c => c.BaseAddress = new("http://foo")).AddServiceDiscovery(); var services = serviceCollection.BuildServiceProvider(); var client = services.GetRequiredService().CreateClient("foo"); - var exception = await Assert.ThrowsAsync(async () => await client.GetStringAsync("/")); + var exception = await Assert.ThrowsAsync(async () => await client.GetStringAsync("/", TestContext.Current.CancellationToken)); Assert.Equal("No provider which supports the provided service name, 'http://foo', has been configured.", exception.Message); }