diff --git a/src/EditorFeatures/Test/Threading/ForegroundNotificationServiceTests.cs b/src/EditorFeatures/Test/Threading/ForegroundNotificationServiceTests.cs index 8e1856ea529de812a4394c7fd0f3ee38561b33e6..5bdb44f1202b454b8e4c8fa26118c139d81bf986 100644 --- a/src/EditorFeatures/Test/Threading/ForegroundNotificationServiceTests.cs +++ b/src/EditorFeatures/Test/Threading/ForegroundNotificationServiceTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -15,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.Threading { public class ForegroundNotificationServiceTests { - private readonly IForegroundNotificationService _service; + private readonly ForegroundNotificationService _service; private bool _done; public ForegroundNotificationServiceTests() @@ -38,7 +39,7 @@ public async Task Test_Enqueue() Assert.True(_done); Assert.True(ran); - Assert.True(Empty(_service)); + Assert.True(_service.IsEmpty_TestOnly); } [WpfFact] @@ -60,7 +61,7 @@ public async Task Test_Cancellation() await PumpWait(); Assert.False(ran); - Assert.True(Empty(_service)); + Assert.True(_service.IsEmpty_TestOnly); } } @@ -69,19 +70,19 @@ public async Task Test_Delay() { var asyncToken = EmptyAsyncToken.Instance; - DateTime now = DateTime.UtcNow; - DateTime set = DateTime.UtcNow; + Stopwatch watch = Stopwatch.StartNew(); _service.RegisterNotification(() => { - set = DateTime.UtcNow; + watch.Stop(); _done = true; }, 50, asyncToken, CancellationToken.None); await PumpWait(); - Assert.True(set.Subtract(now).TotalMilliseconds > 50); - Assert.True(Empty(_service)); + Assert.False(watch.IsRunning); + Assert.True(watch.ElapsedMilliseconds >= 50); + Assert.True(_service.IsEmpty_TestOnly); } [WpfFact] @@ -134,7 +135,7 @@ public async Task Test_HeavyMultipleCall() await PumpWait().ConfigureAwait(false); Assert.True(_done); Assert.Equal(count, 9000000); - Assert.True(Empty(_service)); + Assert.True(_service.IsEmpty_TestOnly); } private async Task PumpWait() @@ -144,11 +145,5 @@ private async Task PumpWait() await Task.Delay(TimeSpan.FromMilliseconds(1)); } } - - private static bool Empty(IForegroundNotificationService service) - { - var temp = (ForegroundNotificationService)service; - return temp.IsEmpty_TestOnly; - } } }