summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/time_unittest.cc25
1 files changed, 16 insertions, 9 deletions
diff --git a/base/time_unittest.cc b/base/time_unittest.cc
index d383612..0076e10 100644
--- a/base/time_unittest.cc
+++ b/base/time_unittest.cc
@@ -117,19 +117,26 @@ TEST(TimeTicks, Deltas) {
}
}
-TEST(TimeTicks, FLAKY_HighResNow) {
+TEST(TimeTicks, HighResNow) {
#if defined(OS_WIN)
- Time::ActivateHighResolutionTimer(true);
+ // HighResNow doesn't work on some systems. Since the product still works
+ // even if it doesn't work, it makes this entire test questionable.
+ if (!TimeTicks::IsHighResClockWorking())
+ return;
#endif
TimeTicks ticks_start = TimeTicks::HighResNow();
- PlatformThread::Sleep(10);
- TimeTicks ticks_stop = TimeTicks::HighResNow();
- TimeDelta delta = ticks_stop - ticks_start;
-
- // In high res mode, we should be accurate to within 1.5x our
- // best granularity. On windows, that is 1ms, so use 1.5ms.
- EXPECT_GE(delta.InMicroseconds(), 8500);
+ TimeDelta delta;
+ // Loop until we can detect that the clock has changed. Non-HighRes timers
+ // will increment in chunks, e.g. 15ms. By spinning until we see a clock
+ // change, we detect the minimum time between measurements.
+ do {
+ delta = TimeTicks::HighResNow() - ticks_start;
+ } while (delta.InMilliseconds() == 0);
+
+ // In high resolution mode, we expect to see the clock increment
+ // in intervals less than 15ms.
+ EXPECT_LT(delta.InMicroseconds(), 15000);
}
TEST(TimeDelta, FromAndIn) {