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

Unified Diff: webrtc/base/gunit.h

Issue 2024813004: Improving the fake clock and using it to fix a flaky STUN timeout test. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 | « webrtc/base/fakeclock.cc ('k') | webrtc/base/messagequeue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/gunit.h
diff --git a/webrtc/base/gunit.h b/webrtc/base/gunit.h
index e705322e6f827fd3dac94c2bb75a474376be977f..4df37f046e5370cd36b3f8950840c517ad612583 100644
--- a/webrtc/base/gunit.h
+++ b/webrtc/base/gunit.h
@@ -11,6 +11,7 @@
#ifndef WEBRTC_BASE_GUNIT_H_
#define WEBRTC_BASE_GUNIT_H_
+#include "webrtc/base/fakeclock.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/thread.h"
#if defined(GTEST_RELATIVE_PATH)
@@ -23,7 +24,8 @@
#define WAIT(ex, timeout) \
for (int64_t start = rtc::TimeMillis(); \
!(ex) && rtc::TimeMillis() < start + timeout;) \
- rtc::Thread::Current()->ProcessMessages(1);
+ rtc::Thread::Current()->ProcessMessages(0); \
+ rtc::Thread::Current()->SleepMs(1);
Taylor Brandstetter 2016/06/01 15:54:58 I had to do this because if you do a "WAIT" while
// This returns the result of the test in res, so that we don't re-evaluate
// the expression in the XXXX_WAIT macros below, since that causes problems
@@ -33,7 +35,8 @@
int64_t start = rtc::TimeMillis(); \
res = (ex); \
while (!res && rtc::TimeMillis() < start + timeout) { \
- rtc::Thread::Current()->ProcessMessages(1); \
+ rtc::Thread::Current()->ProcessMessages(0); \
+ rtc::Thread::Current()->SleepMs(1); \
res = (ex); \
} \
} while (0)
@@ -85,4 +88,41 @@
} \
} while (0)
+// Wait until "ex" is true, or "timeout" expires, using fake clock where
+// messages are processed every millisecond.
+#define SIMULATED_WAIT(ex, clock, timeout) \
+ for (int64_t start = rtc::TimeMillis(); \
+ !(ex) && rtc::TimeMillis() < start + timeout;) \
+ clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1));
+
+// This returns the result of the test in res, so that we don't re-evaluate
+// the expression in the XXXX_WAIT macros below, since that causes problems
+// when the expression is only true the first time you check it.
+#define SIMULATED_WAIT_(ex, clock, timeout, res) \
+ do { \
+ int64_t start = rtc::TimeMillis(); \
+ res = (ex); \
+ while (!res && rtc::TimeMillis() < start + timeout) { \
+ clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(1)); \
+ res = (ex); \
+ } \
+ } while (0)
+
+// The typical EXPECT_XXXX and ASSERT_XXXXs, but done until true or a timeout.
+#define EXPECT_TRUE_SIMULATED_WAIT(ex, clock, timeout) \
+ do { \
+ bool res; \
+ SIMULATED_WAIT_(ex, clock, timeout, res); \
+ if (!res) \
+ EXPECT_TRUE(ex); \
+ } while (0)
+
+#define EXPECT_EQ_SIMULATED_WAIT(v1, v2, clock, timeout) \
+ do { \
+ bool res; \
+ SIMULATED_WAIT_(v1 == v2, clock, timeout, res); \
+ if (!res) \
+ EXPECT_EQ(v1, v2); \
+ } while (0)
+
#endif // WEBRTC_BASE_GUNIT_H_
« no previous file with comments | « webrtc/base/fakeclock.cc ('k') | webrtc/base/messagequeue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698