diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-30 16:02:18 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-30 16:02:18 +0000 |
commit | 86db4d968e8a80d7d579f7ab918cac0e5c063a94 (patch) | |
tree | 411d61e0d0020ddbf19ee92cc017111a311cf830 /base | |
parent | 7e96094572afe3ce10f8f0d4bed90d8da5dfb393 (diff) | |
download | chromium_src-86db4d968e8a80d7d579f7ab918cac0e5c063a94.zip chromium_src-86db4d968e8a80d7d579f7ab918cac0e5c063a94.tar.gz chromium_src-86db4d968e8a80d7d579f7ab918cac0e5c063a94.tar.bz2 |
Fix flakey timer test.
The goal of the test is to verify that the HighResNow() clock has faster
than 15ms precision. Modify the test to not depend on how long Sleep()
takes in order to verify this.
BUG=50291
TEST=TimeTicks.HighResNow
Review URL: http://codereview.chromium.org/3452018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/time_unittest.cc | 25 |
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) { |