diff --git a/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs b/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs index 4bd93051b13..1fd1b2f627c 100644 --- a/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs +++ b/src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs @@ -581,8 +581,9 @@ public async Task StartAsync(CancellationToken cancellationToken = default) public async Task StopAsync(CancellationToken cancellationToken = default) { - using var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, appFactory._disposingCts.Token); - await innerHost.StopAsync(linkedToken.Token).ConfigureAwait(false); + // The cancellation token is passed as-is here to give the host a chance to stop gracefully. + // Internally, in the host itself, the value of HostOptions.ShutdownTimeout limits how long the host has to stop gracefully. + await innerHost.StopAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs index 0bd582f857a..0c43d0751cf 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs @@ -456,9 +456,6 @@ public async Task CrashTests(bool genericEntryPoint, string crashArg) { var exception = await Assert.ThrowsAsync(() => app.StartAsync().WaitAsync(cts.Token)); Assert.Contains(crashArg, exception.Message); - - await app.DisposeAsync().AsTask().WaitAsync(cts.Token); - return; } else { diff --git a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs index 1572b77e045..4115f9316c8 100644 --- a/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs +++ b/tests/Aspire.Hosting.Testing.Tests/TestingFactoryCrashTests.cs @@ -26,8 +26,6 @@ public async Task CrashTests(string crashArg) { var exception = await Assert.ThrowsAsync(() => factory.StartAsync().WaitAsync(cts.Token)); Assert.Contains(crashArg, exception.Message); - await factory.DisposeAsync().AsTask().WaitAsync(cts.Token); - return; } else {