Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: webrtc/base/profiler_unittest.cc

Issue 2392613003: Switched flaky ProfilerTest to use fake clock (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/profiler_unittest.cc
diff --git a/webrtc/base/profiler_unittest.cc b/webrtc/base/profiler_unittest.cc
index 2448fce2de62e52f3ce569d96eae5ea5aed9ada9..ff62f5edec9a0c4cf787a1595c49be887724f85a 100644
--- a/webrtc/base/profiler_unittest.cc
+++ b/webrtc/base/profiler_unittest.cc
@@ -8,8 +8,10 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include "webrtc/base/fakeclock.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/profiler.h"
+#include "webrtc/base/timedelta.h"
#include "webrtc/base/thread.h"
namespace {
@@ -18,9 +20,9 @@ const int kWaitMs = 250;
const double kWaitSec = 0.250;
const double kTolerance = 0.1;
-const char* TestFunc() {
+const char* TestFunc(rtc::FakeClock* clock) {
PROFILE_F();
- rtc::Thread::SleepMs(kWaitMs);
+ clock->AdvanceTime(rtc::TimeDelta::FromMilliseconds(kWaitMs));
return __FUNCTION__;
}
@@ -28,17 +30,12 @@ const char* TestFunc() {
namespace rtc {
-// Disable this test due to flakiness; see bug 5947.
-#if defined(WEBRTC_LINUX)
-#define MAYBE_TestFunction DISABLED_TestFunction
-#else
-#define MAYBE_TestFunction TestFunction
-#endif
-TEST(ProfilerTest, MAYBE_TestFunction) {
+TEST(ProfilerTest, TestFunction) {
+ rtc::ScopedFakeClock fake_clock;
ASSERT_TRUE(Profiler::Instance()->Clear());
// Profile a long-running function.
- const char* function_name = TestFunc();
+ const char* function_name = TestFunc(&fake_clock);
const ProfilerEvent* event = Profiler::Instance()->GetEvent(function_name);
ASSERT_TRUE(event != NULL);
EXPECT_FALSE(event->is_started());
@@ -46,7 +43,7 @@ TEST(ProfilerTest, MAYBE_TestFunction) {
EXPECT_NEAR(kWaitSec, event->mean(), kTolerance * 3);
Taylor Brandstetter 2016/10/04 00:48:53 If the time is now 100% predictable, can we get ri
skvlad 2016/10/04 01:17:45 Good point. I've replaced them all with EXPECT_EQ.
// Run it a second time.
- TestFunc();
+ TestFunc(&fake_clock);
EXPECT_FALSE(event->is_started());
EXPECT_EQ(2, event->event_count());
EXPECT_NEAR(kWaitSec, event->mean(), kTolerance);
@@ -55,6 +52,7 @@ TEST(ProfilerTest, MAYBE_TestFunction) {
}
TEST(ProfilerTest, TestScopedEvents) {
+ rtc::ScopedFakeClock fake_clock;
const std::string kEvent1Name = "Event 1";
const std::string kEvent2Name = "Event 2";
const int kEvent2WaitMs = 150;
@@ -68,7 +66,7 @@ TEST(ProfilerTest, TestScopedEvents) {
ASSERT_TRUE(event1 != NULL);
EXPECT_TRUE(event1->is_started());
EXPECT_EQ(0, event1->event_count());
- rtc::Thread::SleepMs(kWaitMs);
+ fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kWaitMs));
EXPECT_TRUE(event1->is_started());
}
// Check the result.
@@ -81,7 +79,7 @@ TEST(ProfilerTest, TestScopedEvents) {
ASSERT_TRUE(event2 != NULL);
EXPECT_FALSE(event1->is_started());
EXPECT_TRUE(event2->is_started());
- rtc::Thread::SleepMs(kEvent2WaitMs);
+ fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kEvent2WaitMs));
}
// Check the result.
EXPECT_FALSE(event2->is_started());
@@ -95,7 +93,7 @@ TEST(ProfilerTest, TestScopedEvents) {
{ // Run another event 1.
PROFILE(kEvent1Name);
EXPECT_TRUE(event1->is_started());
- rtc::Thread::SleepMs(kWaitMs);
+ fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(kWaitMs));
}
// Check the result.
EXPECT_FALSE(event1->is_started());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698