From 7c823213ee29c65e56b4f2db5672861f905da87a Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 4 Nov 2020 06:30:24 -0800 Subject: [PATCH] Increase unexpected delay timeout Fixes #48988 --- .../AsynchronousOperationListenerTests.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/EditorFeatures/Test/Utilities/AsynchronousOperationListenerTests.cs b/src/EditorFeatures/Test/Utilities/AsynchronousOperationListenerTests.cs index e0d3d5bcb182b..56ac83151dd70 100644 --- a/src/EditorFeatures/Test/Utilities/AsynchronousOperationListenerTests.cs +++ b/src/EditorFeatures/Test/Utilities/AsynchronousOperationListenerTests.cs @@ -16,7 +16,10 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities { public class AsynchronousOperationListenerTests { - private static readonly int s_testTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds; + /// + /// A delay which is not expected to be reached in practice. + /// + private static readonly TimeSpan s_unexpectedDelay = TimeSpan.FromSeconds(60); private class SleepHelper : IDisposable { @@ -55,14 +58,14 @@ public void Sleep(TimeSpan timeToSleep) Task task; lock (_tasks) { - task = Task.Factory.SafeStartNew(() => + task = Task.Factory.StartNew(() => { while (true) { _tokenSource.Token.ThrowIfCancellationRequested(); Thread.Sleep(TimeSpan.FromMilliseconds(10)); } - }, _tokenSource.Token, TaskScheduler.Default); + }, _tokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); _tasks.Add(task); } @@ -125,7 +128,7 @@ public void QueuedOperation() Assert.True(done, "Should have waited for the queued operation to finish!"); } - [Fact(/*Skip = "Throwing ContractFailure on a TPL thread?"*/)] + [Fact] public void Cancel() { using var sleepHelper = new SleepHelper(); @@ -142,7 +145,7 @@ public void Cancel() var asyncToken2 = listener.BeginAsyncOperation("Test"); var queuedTask = new Task(() => { - sleepHelper.Sleep(TimeSpan.FromSeconds(5)); + sleepHelper.Sleep(s_unexpectedDelay); continued = true; }); asyncToken2.Dispose(); @@ -324,9 +327,9 @@ private static void Wait(AsynchronousOperationListener listener, ManualResetEven // threadpool scheduling, we may get here before that other thread has started to run. // That's why each task set's a signal to say that it has begun and we first wait for // that, and then start waiting. - Assert.True(signal.Wait(s_testTimeout), "Shouldn't have hit timeout waiting for task to begin"); + Assert.True(signal.Wait(s_unexpectedDelay), "Shouldn't have hit timeout waiting for task to begin"); var waitTask = listener.ExpeditedWaitAsync(); - Assert.True(waitTask.Wait(s_testTimeout), "Wait shouldn't have needed to timeout"); + Assert.True(waitTask.Wait(s_unexpectedDelay), "Wait shouldn't have needed to timeout"); } private static void Wait(AsynchronousOperationListener listener, ManualResetEventSlim signal1, ManualResetEventSlim signal2) @@ -335,11 +338,11 @@ private static void Wait(AsynchronousOperationListener listener, ManualResetEven // threadpool scheduling, we may get here before that other thread has started to run. // That's why each task set's a signal to say that it has begun and we first wait for // that, and then start waiting. - Assert.True(signal1.Wait(s_testTimeout), "Shouldn't have hit timeout waiting for task to begin"); - Assert.True(signal2.Wait(s_testTimeout), "Shouldn't have hit timeout waiting for task to begin"); + Assert.True(signal1.Wait(s_unexpectedDelay), "Shouldn't have hit timeout waiting for task to begin"); + Assert.True(signal2.Wait(s_unexpectedDelay), "Shouldn't have hit timeout waiting for task to begin"); var waitTask = listener.ExpeditedWaitAsync(); - Assert.True(waitTask.Wait(s_testTimeout), "Wait shouldn't have needed to timeout"); + Assert.True(waitTask.Wait(s_unexpectedDelay), "Wait shouldn't have needed to timeout"); } } }