提交 7045d1a9 编写于 作者: D David Kean

Fix flaky ForegroundNotificationServiceTests.Test_Delay

This test has been changed twice, first time was using DateTime, second was using Stopwatch. From my testing, both have a slightly different opinion than to Environment.TickCount as to how long has passed by 1 - 3 milliseconds. Environment.TickCount on my box has a resolution of 15/16 milliseconds accuracy, but Stopwatch and DateTime both found that these same 15/16 milliseconds took between 14 -> 16 milliseconds.

Instead of accounting for this, I just changed this test to use the same clock as the underlying service.
上级 224a5a58
......@@ -4,8 +4,6 @@
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Microsoft.CodeAnalysis.Editor.Implementation.ForegroundNotification;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Shared.TestHooks;
......@@ -68,20 +66,25 @@ public async Task Test_Cancellation()
[WpfFact]
public async Task Test_Delay()
{
// NOTE: Don't be tempted to use DateTime or Stopwatch to measure this
// Switched to Environment.TickCount use the same clock as the notification
// service, see: https://github.com/dotnet/roslyn/issues/7512.
var asyncToken = EmptyAsyncToken.Instance;
Stopwatch watch = Stopwatch.StartNew();
int startMilliseconds = Environment.TickCount;
int? elapsedMilliseconds = null;
_service.RegisterNotification(() =>
{
watch.Stop();
elapsedMilliseconds = Environment.TickCount - startMilliseconds;
_done = true;
}, 50, asyncToken, CancellationToken.None);
await PumpWait();
Assert.False(watch.IsRunning);
Assert.True(watch.ElapsedMilliseconds >= 50);
Assert.True(elapsedMilliseconds >= 50, $"Notification fired after {elapsedMilliseconds}, instead of 50.");
Assert.True(_service.IsEmpty_TestOnly);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册