diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-20 08:52:39 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-20 08:52:39 +0000 |
commit | 1ebe5a322b9cb07bdb2b46d1023d8dba1fe52f9e (patch) | |
tree | 8b8ba61181b3d7092aabc6702fc13a9791eedee5 /base/time_unittest.cc | |
parent | 47245d6709f7f16a65cfb3df9aeb51fb32d5a4ea (diff) | |
download | chromium_src-1ebe5a322b9cb07bdb2b46d1023d8dba1fe52f9e.zip chromium_src-1ebe5a322b9cb07bdb2b46d1023d8dba1fe52f9e.tar.gz chromium_src-1ebe5a322b9cb07bdb2b46d1023d8dba1fe52f9e.tar.bz2 |
Fix flakey test TimeTicks.HighResNow
BUG=50291
TEST=<this is the test>
Review URL: http://codereview.chromium.org/3919005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63192 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_unittest.cc')
-rw-r--r-- | base/time_unittest.cc | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/base/time_unittest.cc b/base/time_unittest.cc index 0076e10..21e6f89 100644 --- a/base/time_unittest.cc +++ b/base/time_unittest.cc @@ -125,18 +125,35 @@ TEST(TimeTicks, HighResNow) { return; #endif - TimeTicks ticks_start = TimeTicks::HighResNow(); + // Why do we loop here? + // We're trying to measure that intervals increment in a VERY small amount + // of time -- less than 15ms. Unfortunately, if we happen to have a + // context switch in the middle of our test, the context switch could easily + // exceed our limit. So, we iterate on this several times. As long as we're + // able to detect the fine-granularity timers at least once, then the test + // has succeeded. + + const int kTargetGranularityUs = 15000; // 15ms + + bool success = false; + int retries = 100; // Arbitrary. 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); + while (!success && retries--) { + TimeTicks ticks_start = TimeTicks::HighResNow(); + // 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); + + if (delta.InMicroseconds() <= kTargetGranularityUs) + success = true; + } // In high resolution mode, we expect to see the clock increment // in intervals less than 15ms. - EXPECT_LT(delta.InMicroseconds(), 15000); + EXPECT_TRUE(success); } TEST(TimeDelta, FromAndIn) { |