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

Unified Diff: webrtc/base/testclient.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/testclient.h ('k') | webrtc/base/thread.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/testclient.cc
diff --git a/webrtc/base/testclient.cc b/webrtc/base/testclient.cc
index 7ec70f40d1f5bf563594bcf29798f685fb2d8824..b6fd692350bb0ae68770111909aa72be50e9c4bf 100644
--- a/webrtc/base/testclient.cc
+++ b/webrtc/base/testclient.cc
@@ -9,6 +9,8 @@
*/
#include "webrtc/base/testclient.h"
+
+#include "webrtc/base/gunit.h"
#include "webrtc/base/ptr_util.h"
#include "webrtc/base/thread.h"
#include "webrtc/base/timeutils.h"
@@ -20,7 +22,13 @@ namespace rtc {
// NextPacket.
TestClient::TestClient(std::unique_ptr<AsyncPacketSocket> socket)
- : socket_(std::move(socket)), prev_packet_timestamp_(-1) {
+ : TestClient(std::move(socket), nullptr) {}
+
+TestClient::TestClient(std::unique_ptr<AsyncPacketSocket> socket,
+ FakeClock* fake_clock)
+ : fake_clock_(fake_clock),
+ socket_(std::move(socket)),
+ prev_packet_timestamp_(-1) {
socket_->SignalReadPacket.connect(this, &TestClient::OnPacket);
socket_->SignalReadyToSend.connect(this, &TestClient::OnReadyToSend);
}
@@ -31,7 +39,7 @@ bool TestClient::CheckConnState(AsyncPacketSocket::State state) {
// Wait for our timeout value until the socket reaches the desired state.
int64_t end = TimeAfter(kTimeoutMs);
while (socket_->GetState() != state && TimeUntil(end) > 0) {
- Thread::Current()->ProcessMessages(1);
+ AdvanceTime(1);
}
return (socket_->GetState() == state);
}
@@ -67,7 +75,7 @@ std::unique_ptr<TestClient::Packet> TestClient::NextPacket(int timeout_ms) {
break;
}
}
- Thread::Current()->ProcessMessages(1);
+ AdvanceTime(1);
}
// Return the first packet placed in the queue.
@@ -108,6 +116,16 @@ bool TestClient::CheckTimestamp(int64_t packet_timestamp) {
return res;
}
+void TestClient::AdvanceTime(int ms) {
+ // If the test is using a fake clock, we must advance the fake clock to
+ // advance time. Otherwise, ProcessMessages will work.
+ if (fake_clock_) {
+ SIMULATED_WAIT(false, ms, *fake_clock_);
+ } else {
+ Thread::Current()->ProcessMessages(1);
+ }
+}
+
bool TestClient::CheckNoPacket() {
return NextPacket(kNoPacketTimeoutMs) == nullptr;
}
« no previous file with comments | « webrtc/base/testclient.h ('k') | webrtc/base/thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698