diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index ae911a6feb..e3d0f106f9 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -450,21 +450,27 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNull_IfOperationCancelle mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny())).Returns((ICollection i1, CancellationToken cancellation) => { - for (int i = 0; i < 1000; ++i) + try { - Task.Delay(100).Wait(); - Console.WriteLine($"Iteration: {i}"); + for (int i = 0; i < 1000; ++i) + { + Task.Delay(100).Wait(); + Console.WriteLine($"Iteration: {i}"); - cancellation.ThrowIfCancellationRequested(); + cancellation.ThrowIfCancellationRequested(); - if (i == 3) - { - cancellationTokenSource.Cancel(); - Task.Delay(500).Wait(); + if (i == 3) + { + cancellationTokenSource.Cancel(); + Task.Delay(500).Wait(); + } } } + finally + { + innerTaskCompletionSource.TrySetResult(null); + } - innerTaskCompletionSource.TrySetResult(null); return outputAttachments; });