diff --git a/test/Microsoft.NET.Sdk.Razor.Tool.Tests/DefaultRequestDispatcherTest.cs b/test/Microsoft.NET.Sdk.Razor.Tool.Tests/DefaultRequestDispatcherTest.cs index 5cb1fbe5eea8..4b94d6b736cb 100644 --- a/test/Microsoft.NET.Sdk.Razor.Tool.Tests/DefaultRequestDispatcherTest.cs +++ b/test/Microsoft.NET.Sdk.Razor.Tool.Tests/DefaultRequestDispatcherTest.cs @@ -340,7 +340,8 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout { // Arrange var totalCount = 2; - var readySource = new TaskCompletionSource(); + var timeout = TimeSpan.FromMinutes(1); + var readySource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var list = new List>(); var connectionHost = new Mock(); connectionHost @@ -349,7 +350,7 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout { if (list.Count < totalCount) { - var source = new TaskCompletionSource(); + var source = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connectionTask = CreateConnectionWithEmptyServerRequest(c => { // Keep the connection active until we decide to end it. @@ -373,10 +374,10 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout var eventBus = new TestableEventBus(); var completedCompilations = 0; - var allCompilationsComplete = new TaskCompletionSource(); + var allCompilationsComplete = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); eventBus.CompilationComplete += (obj, args) => { - if (++completedCompilations == totalCount) + if (Interlocked.Increment(ref completedCompilations) == totalCount) { // All compilations have completed. allCompilationsComplete.SetResult(true); @@ -391,10 +392,10 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout }, TestContext.CancellationToken); // Wait for all connections to be created. - await readySource.Task; + await readySource.Task.WaitAsync(timeout, TestContext.CancellationToken); // Wait for all compilations to complete. - await allCompilationsComplete.Task; + await allCompilationsComplete.Task.WaitAsync(timeout, TestContext.CancellationToken); // Now allow all the connections to be disconnected. foreach (var source in list) @@ -404,7 +405,7 @@ public async Task Dispatcher_ProcessSimultaneousConnections_HitsKeepAliveTimeout // Act // Now dispatcher should be in an idle state with no active connections. - await dispatcherTask; + await dispatcherTask.WaitAsync(timeout, TestContext.CancellationToken); // Assert Assert.IsFalse(eventBus.HasDetectedBadConnection);