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

Unified Diff: webrtc/base/fakeclock.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: Addressing comments. 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
Index: webrtc/base/fakeclock.h
diff --git a/webrtc/base/fakeclock.h b/webrtc/base/fakeclock.h
index 2b3afdde05f684926621bcc95c2f917bfb7bd60f..83be0faf0b85c63c0a07aba633bd88bf444ca7e4 100644
--- a/webrtc/base/fakeclock.h
+++ b/webrtc/base/fakeclock.h
@@ -19,6 +19,8 @@ namespace rtc {
// Fake clock for use with unit tests, which does not tick on its own.
// Starts at time 0.
+//
+// TODO(deadbeef): Unify with webrtc::SimulatedClock.
class FakeClock : public ClockInterface {
public:
~FakeClock() override {}
@@ -38,6 +40,17 @@ class FakeClock : public ClockInterface {
uint64_t time_ GUARDED_BY(lock_) = 0u;
};
+// Helper class that sets itself as the global clock in its constructor and
+// unsets it in its destructor.
+class ScopedFakeClock : public FakeClock {
+ public:
+ ScopedFakeClock() { prev_clock_ = SetClock(this); }
+ ~ScopedFakeClock() { SetClock(prev_clock_); }
+
+ private:
+ ClockInterface* prev_clock_;
+};
+
} // namespace rtc
#endif // WEBRTC_BASE_FAKECLOCK_H_

Powered by Google App Engine
This is Rietveld 408576698