summaryrefslogtreecommitdiff
path: root/tests/src/CoreMangLib/cti
diff options
context:
space:
mode:
authorAlex Perovich <alperovi@microsoft.com>2017-04-08 14:24:01 -0500
committerDan Moseley <danmose@microsoft.com>2017-04-08 12:24:01 -0700
commit1ed5cf1a3a2aebe5487dff7984d0305ceec9823b (patch)
treebd22acbbaa95e346f2c79dd28cc73e5db75d5358 /tests/src/CoreMangLib/cti
parent4d6398e55d510070b3c7fe39db4918a58ea94e7b (diff)
downloadcoreclr-1ed5cf1a3a2aebe5487dff7984d0305ceec9823b.tar.gz
coreclr-1ed5cf1a3a2aebe5487dff7984d0305ceec9823b.tar.bz2
coreclr-1ed5cf1a3a2aebe5487dff7984d0305ceec9823b.zip
Use a monotonic clock for test timing (#10812)
Fixes #8348
Diffstat (limited to 'tests/src/CoreMangLib/cti')
-rw-r--r--tests/src/CoreMangLib/cti/system/threading/autoresetevent/autoreseteventctor.cs15
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/src/CoreMangLib/cti/system/threading/autoresetevent/autoreseteventctor.cs b/tests/src/CoreMangLib/cti/system/threading/autoresetevent/autoreseteventctor.cs
index 284889d8f2..ad001402d6 100644
--- a/tests/src/CoreMangLib/cti/system/threading/autoresetevent/autoreseteventctor.cs
+++ b/tests/src/CoreMangLib/cti/system/threading/autoresetevent/autoreseteventctor.cs
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+
using System;
+using System.Diagnostics;
using System.Threading;
public class AutoResetEventCtor
@@ -70,8 +72,8 @@ public class AutoResetEventCtor
{
bool retVal = true;
AutoResetEvent are;
- long ticksBefore;
- long ticksAfter;
+ Stopwatch sw;
+ long elapsedTicks;
TestLibrary.TestFramework.BeginScenario("PosTest1: AutoResetEvent.Ctor(false)");
@@ -80,19 +82,20 @@ public class AutoResetEventCtor
// true means that the initial state should be signaled
are = new AutoResetEvent(false);
- ticksBefore = DateTime.Now.Ticks;
+ sw = Stopwatch.StartNew();
// verify that the autoreset event is signaled
// if it is not signaled the following call will block for ever
TestLibrary.TestFramework.LogInformation("Calling AutoResetEvent.WaitOne()... if the event is signaled it will not wait long enough");
are.WaitOne(c_MILLISECONDS_TOWAIT);
- ticksAfter = DateTime.Now.Ticks;
+ sw.Stop();
+ elapsedTicks = sw.Elapsed.Ticks;
- if (c_DELTA < Math.Abs((ticksAfter - ticksBefore) - (c_MILLISECONDS_TOWAIT*10000)))
+ if (c_DELTA < Math.Abs(elapsedTicks - (c_MILLISECONDS_TOWAIT*10000)))
{
TestLibrary.TestFramework.LogError("002", "AutoResetEvent did not wait long enough... this implies that the parameter was not respected.");
- TestLibrary.TestFramework.LogError("002", " WaitTime=" + (ticksAfter-ticksBefore) + " (ticks)");
+ TestLibrary.TestFramework.LogError("002", " WaitTime=" + elapsedTicks + " (ticks)");
TestLibrary.TestFramework.LogError("002", " Execpted=" + (c_MILLISECONDS_TOWAIT*10000) + " (ticks)");
TestLibrary.TestFramework.LogError("002", " Acceptable Delta=" + c_DELTA + " (ticks)");
retVal = false;