diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs index 4138e7df4c5c0..dd8e96507f3bb 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs +++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs @@ -710,11 +710,12 @@ public async Task HostStopsApplicationWithOneBackgroundServiceErrorAndOthersWith var wasStoppingCalled = false; lifetime.ApplicationStopping.Register(() => { - otherTcs.SetResult(true); wasStoppingCalled = true; + otherTcs.SetResult(true); }); - await host.StartAsync(); + // Ensure all completions have been signaled before continuing + await Task.WhenAll(host.StartAsync(), throwingTcs.Task, otherTcs.Task); Assert.True(wasStartedCalled); Assert.True(wasStoppingCalled);