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

Unified Diff: webrtc/base/virtualsocketserver.cc

Issue 2927413002: Update VirtualSocketServerTest to use a fake clock. (Closed)
Patch Set: Allow ProcessMessages with cmsLoop of kForever. Created 3 years, 6 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/virtualsocketserver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/virtualsocketserver.cc
diff --git a/webrtc/base/virtualsocketserver.cc b/webrtc/base/virtualsocketserver.cc
index cfb4eb294b673dc97b041a8e3a98505855e0d64f..95feeae49adc042078792d37909882527cb0419e 100644
--- a/webrtc/base/virtualsocketserver.cc
+++ b/webrtc/base/virtualsocketserver.cc
@@ -19,6 +19,7 @@
#include <vector>
#include "webrtc/base/checks.h"
+#include "webrtc/base/gunit.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/physicalsocketserver.h"
#include "webrtc/base/socketaddresspair.h"
@@ -528,8 +529,11 @@ void VirtualSocket::OnSocketServerReadyToSend() {
}
}
-VirtualSocketServer::VirtualSocketServer()
- : wakeup_(/*manual_reset=*/false, /*initially_signaled=*/false),
+VirtualSocketServer::VirtualSocketServer() : VirtualSocketServer(nullptr) {}
+
+VirtualSocketServer::VirtualSocketServer(FakeClock* fake_clock)
+ : fake_clock_(fake_clock),
+ wakeup_(/*manual_reset=*/false, /*initially_signaled=*/false),
msg_queue_(nullptr),
stop_on_idle_(false),
next_ipv4_(kInitialNextIPv4),
@@ -642,9 +646,17 @@ bool VirtualSocketServer::ProcessMessagesUntilIdle() {
RTC_DCHECK(msg_queue_ == Thread::Current());
stop_on_idle_ = true;
while (!msg_queue_->empty()) {
- Message msg;
- if (msg_queue_->Get(&msg, Thread::kForever)) {
- msg_queue_->Dispatch(&msg);
+ if (fake_clock_) {
+ // If using a fake clock, advance it in millisecond increments until the
+ // queue is empty (the SIMULATED_WAIT macro ensures the queue processes
+ // all possible messages each time it's called).
+ SIMULATED_WAIT(false, 1, *fake_clock_);
+ } else {
+ // Otherwise, run a normal message loop.
+ Message msg;
+ if (msg_queue_->Get(&msg, Thread::kForever)) {
+ msg_queue_->Dispatch(&msg);
+ }
}
}
stop_on_idle_ = false;
« no previous file with comments | « webrtc/base/virtualsocketserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698