diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-16 04:32:49 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-16 04:32:49 +0000 |
commit | e91ce809048b33f62569a01404b833d3aa9f15d0 (patch) | |
tree | 4e6be1ba994b3598dd3365f180bd2b16be39e9a0 | |
parent | 8a503d82ee9191362194a1337a44541caa34de07 (diff) | |
download | chromium_src-e91ce809048b33f62569a01404b833d3aa9f15d0.zip chromium_src-e91ce809048b33f62569a01404b833d3aa9f15d0.tar.gz chromium_src-e91ce809048b33f62569a01404b833d3aa9f15d0.tar.bz2 |
Fix TraceEventTestFixture flakiness
BUG=142804
Review URL: https://chromiumcodereview.appspot.com/10828326
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151851 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/debug/trace_event_unittest.cc | 20 | ||||
-rw-r--r-- | base/debug/trace_event_unittest.h | 14 | ||||
-rw-r--r-- | base/test/trace_event_analyzer_unittest.cc | 3 |
4 files changed, 31 insertions, 7 deletions
diff --git a/base/base.gyp b/base/base.gyp index 12898c2..7db29d4 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -381,6 +381,7 @@ 'debug/leak_tracker_unittest.cc', 'debug/stack_trace_unittest.cc', 'debug/trace_event_unittest.cc', + 'debug/trace_event_unittest.h', 'debug/trace_event_win_unittest.cc', 'environment_unittest.cc', 'file_descriptor_shuffle_unittest.cc', diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc index 5d32f2f..f806cf1 100644 --- a/base/debug/trace_event_unittest.cc +++ b/base/debug/trace_event_unittest.cc @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/debug/trace_event.h" +#include "base/debug/trace_event_unittest.h" #include "base/bind.h" #include "base/command_line.h" +#include "base/debug/trace_event.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/memory/ref_counted_memory.h" @@ -20,6 +21,8 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using base::debug::HighResSleepForTraceTest; + namespace base { namespace debug { @@ -633,6 +636,13 @@ void TraceCallsWithCachedCategoryPointersPointers(const char* name_str) { } // namespace +void HighResSleepForTraceTest(base::TimeDelta elapsed) { + base::TimeTicks end_time = base::TimeTicks::HighResNow() + elapsed; + do { + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); + } while (base::TimeTicks::HighResNow() < end_time); +} + // Simple Test for emitting data and validating it was received. TEST_F(TraceEventTestFixture, DataCaptured) { ManualTestSetUp(); @@ -843,7 +853,7 @@ TEST_F(TraceEventTestFixture, DataCapturedThreshold) { // 100+ seconds to avoid flakiness. TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "threshold long1"); TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "threshold long2"); - base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); + HighResSleepForTraceTest(base::TimeDelta::FromMilliseconds(20)); } // Test that a normal nested event remains after it's parent event is dropped. @@ -868,8 +878,7 @@ TEST_F(TraceEventTestFixture, DataCapturedThreshold) { TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "3threshold1000"); { TRACE_EVENT_IF_LONGER_THAN0(100, "time", "3threshold100"); - base::PlatformThread::Sleep( - base::TimeDelta::FromMilliseconds(20)); + HighResSleepForTraceTest(base::TimeDelta::FromMilliseconds(20)); } } } @@ -893,8 +902,7 @@ TEST_F(TraceEventTestFixture, DataCapturedThreshold) { { TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "4thresholdlong2"); - base::PlatformThread::Sleep( - base::TimeDelta::FromMilliseconds(20)); + HighResSleepForTraceTest(base::TimeDelta::FromMilliseconds(20)); } } } diff --git a/base/debug/trace_event_unittest.h b/base/debug/trace_event_unittest.h new file mode 100644 index 0000000..3b570e1 --- /dev/null +++ b/base/debug/trace_event_unittest.h @@ -0,0 +1,14 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/time.h" + +namespace base { +namespace debug { + +// Sleep until HighResNow has advanced by at least |elapsed|. +void HighResSleepForTraceTest(base::TimeDelta elapsed); + +} // namespace debug +} // namespace base diff --git a/base/test/trace_event_analyzer_unittest.cc b/base/test/trace_event_analyzer_unittest.cc index dd1ce4d..63760a4 100644 --- a/base/test/trace_event_analyzer_unittest.cc +++ b/base/test/trace_event_analyzer_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/debug/trace_event_unittest.h" #include "base/test/trace_event_analyzer.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -392,7 +393,7 @@ TEST_F(TraceEventAnalyzerTest, Duration) { { TRACE_EVENT0("cat2", "name3"); // found by duration query TRACE_EVENT_INSTANT0("noise", "name4"); // not searched for, just noise - base::PlatformThread::Sleep(kSleepTime); + base::debug::HighResSleepForTraceTest(kSleepTime); TRACE_EVENT0("cat2", "name5"); // not found (duration too short) } } |