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

Unified Diff: webrtc/p2p/base/port_unittest.cc

Issue 2722933002: Measure packet loss so we can use it to select ICE candidate pairs. (Closed)
Patch Set: better comments and test names Created 3 years, 10 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
« webrtc/p2p/base/port.cc ('K') | « webrtc/p2p/base/port.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/port_unittest.cc
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc
index 4029118892a9bda579795533e89c571450310cb4..7df811c7e7db6f8db91d9975e876f4470064aae0 100644
--- a/webrtc/p2p/base/port_unittest.cc
+++ b/webrtc/p2p/base/port_unittest.cc
@@ -2885,3 +2885,73 @@ TEST_F(PortTest, TestAddConnectionWithSameAddress) {
rtc::Thread::Current()->ProcessMessages(300);
EXPECT_TRUE(port->GetConnection(address) != nullptr);
}
+
+class PacketLossEstimatorTest : public testing::Test {};
Taylor Brandstetter 2017/03/01 02:26:13 Could have a test for calling RemoveExpiredPackets
Zach Stein 2017/03/02 00:02:23 Done.
+
+class PacketLossEstimatorWithTestInfo : public PacketLossEstimator {
+ public:
+ PacketLossEstimatorWithTestInfo(int64_t expire_after)
+ : PacketLossEstimator(expire_after) {}
+
+ // making these public for the tests
+ using PacketLossEstimator::get_responses_expected;
+ using PacketLossEstimator::get_responses_received;
+};
+
+TEST_F(PacketLossEstimatorTest, ResponseReceived) {
+ PacketLossEstimatorWithTestInfo ple(5);
+
+ ple.ExpectResponse("1", 0);
+ ple.ReceivedResponse("1", 1);
+
+ EXPECT_EQ(1, ple.get_responses_received());
+ EXPECT_EQ(1, ple.get_responses_expected());
+ EXPECT_EQ(1.0, ple.get_response_rate());
+}
+
+TEST_F(PacketLossEstimatorTest, ResponseLost) {
+ PacketLossEstimatorWithTestInfo ple(5);
+
+ ple.ExpectResponse("1", 0);
+ ple.RemoveExpiredPackets(10);
+
+ EXPECT_EQ(0, ple.get_responses_received());
+ EXPECT_EQ(1, ple.get_responses_expected());
+ EXPECT_EQ(0.0, ple.get_response_rate());
+}
+
+TEST_F(PacketLossEstimatorTest, ResponseLate) {
+ PacketLossEstimatorWithTestInfo ple(5);
+
+ ple.ExpectResponse("1", 0);
+ ple.ReceivedResponse("1", 10);
+
+ EXPECT_EQ(0, ple.get_responses_received());
+ EXPECT_EQ(1, ple.get_responses_expected());
+ EXPECT_EQ(0.0, ple.get_response_rate());
+}
+
+TEST_F(PacketLossEstimatorTest, OneLostOneReceived) {
+ PacketLossEstimatorWithTestInfo ple(5);
+
+ ple.ExpectResponse("1", 0);
+ ple.ExpectResponse("2", 2);
+ ple.ReceivedResponse("2", 6);
+
+ EXPECT_EQ(1, ple.get_responses_received());
+ EXPECT_EQ(2, ple.get_responses_expected());
+ EXPECT_EQ(0.5, ple.get_response_rate());
+}
+
+TEST_F(PacketLossEstimatorTest, DontDoubleExpire) {
+ PacketLossEstimatorWithTestInfo ple(5);
+
+ ple.ExpectResponse("1", 0);
+ ple.ExpectResponse("2", 2);
+ ple.ReceivedResponse("2", 6); // expires "1"
+ ple.ReceivedResponse("1", 7); // "1" should already be expired
Taylor Brandstetter 2017/03/01 02:26:13 nit: Generally our style is to use full capitaliza
Zach Stein 2017/03/02 00:02:23 Done.
+
+ EXPECT_EQ(1, ple.get_responses_received());
+ EXPECT_EQ(2, ple.get_responses_expected());
+ EXPECT_EQ(0.5, ple.get_response_rate());
+}
« webrtc/p2p/base/port.cc ('K') | « webrtc/p2p/base/port.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698