Reland of: Improving the fake clock and using it to fix a flaky STUN timeout test.
When the fake clock's time is advanced, it now ensures all pending
queued messages have been dispatched. This allows us to write a
"SIMULATED_WAIT" macro that ticks the simulated clock by milliseconds up
until the target time.
Useful in this case, where we know the STUN timeout should take a total
of 9500ms, but it would be overly complex to write test code that waits
for each individual timeout, ensures a STUN packet has been
retransmited, etc.
(The test described above *should* be written, but it belongs in
p2ptransportchannel_unittest.cc, not webrtcsession_unittest.cc).
Review-Url: https://codereview.webrtc.org/2024813004
Cr-Commit-Position: refs/heads/master@{#13052}
diff --git a/webrtc/base/timeutils.h b/webrtc/base/timeutils.h
index 78ebace..113793a 100644
--- a/webrtc/base/timeutils.h
+++ b/webrtc/base/timeutils.h
@@ -39,8 +39,10 @@
// Sets the global source of time. This is useful mainly for unit tests.
//
-// Does not transfer ownership of the clock.
-// SetClock(nullptr) should be called before the ClockInterface is deleted.
+// Returns the previously set ClockInterface, or nullptr if none is set.
+//
+// Does not transfer ownership of the clock. SetClockForTesting(nullptr)
+// should be called before the ClockInterface is deleted.
//
// This method is not thread-safe; it should only be used when no other thread
// is running (for example, at the start/end of a unit test, or start/end of
@@ -49,7 +51,7 @@
// TODO(deadbeef): Instead of having functions that access this global
// ClockInterface, we may want to pass the ClockInterface into everything
// that uses it, eliminating the need for a global variable and this function.
-void SetClock(ClockInterface* clock);
+ClockInterface* SetClockForTesting(ClockInterface* clock);
// Returns the current time in milliseconds in 32 bits.
uint32_t Time32();