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

Side by Side Diff: webrtc/p2p/base/packetlossestimator_unittest.cc

Issue 2722933002: Measure packet loss so we can use it to select ICE candidate pairs. (Closed)
Patch Set: Append ForTesting to TrackedPacketsString method name. Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/packetlossestimator.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <utility>
12
13 #include "webrtc/base/gunit.h"
14 #include "webrtc/p2p/base/packetlossestimator.h"
15
16 using cricket::PacketLossEstimator;
17
18 class PacketLossEstimatorTest : public testing::Test {};
19
20 TEST_F(PacketLossEstimatorTest, InitialResponseRate) {
21 PacketLossEstimator ple(5, 100);
22 EXPECT_EQ(1.0, ple.get_response_rate());
23 }
24
25 TEST_F(PacketLossEstimatorTest, InitialUpdateResponseRate) {
26 PacketLossEstimator ple(5, 100);
27 ple.UpdateResponseRate(10);
28 EXPECT_EQ(1.0, ple.get_response_rate());
29 }
30
31 TEST_F(PacketLossEstimatorTest, ResponseReceived) {
32 PacketLossEstimator ple(5, 100);
33
34 ple.ExpectResponse("a", 0);
35 ple.ReceivedResponse("a", 1);
36 ple.UpdateResponseRate(2);
37
38 EXPECT_EQ(1.0, ple.get_response_rate());
39 }
40
41 TEST_F(PacketLossEstimatorTest, ResponseNotConsideredLostYet) {
42 PacketLossEstimator ple(5, 100);
43
44 ple.ExpectResponse("a", 0);
45 ple.UpdateResponseRate(2);
46
47 EXPECT_EQ(1.0, ple.get_response_rate());
48 }
49
50 TEST_F(PacketLossEstimatorTest, ResponseConsideredLost) {
51 PacketLossEstimator ple(5, 100);
52
53 ple.ExpectResponse("a", 0);
54 ple.UpdateResponseRate(10);
55
56 EXPECT_EQ(0.0, ple.get_response_rate());
57 }
58
59 TEST_F(PacketLossEstimatorTest, ResponseLate) {
60 PacketLossEstimator ple(5, 100);
61
62 ple.ExpectResponse("a", 0);
63 ple.ReceivedResponse("a", 6);
64 ple.UpdateResponseRate(10);
65
66 EXPECT_EQ(1.0, ple.get_response_rate());
67 }
68
69 TEST_F(PacketLossEstimatorTest, ResponseForgotten) {
70 PacketLossEstimator ple(5, 100);
71 ple.ExpectResponse("a", 0);
72 ple.UpdateResponseRate(101);
73
74 EXPECT_EQ(1.0, ple.get_response_rate());
75 }
76
77 TEST_F(PacketLossEstimatorTest, Lost1_Received1) {
78 PacketLossEstimator ple(5, 100);
79
80 ple.ExpectResponse("a", 0);
81 ple.ExpectResponse("b", 2);
82 ple.ReceivedResponse("b", 6);
83 ple.UpdateResponseRate(7);
84
85 EXPECT_EQ(0.5, ple.get_response_rate());
86 }
87
88 static const std::pair<std::string, int64_t> kFivePackets[5] = {{"a", 0},
89 {"b", 2},
90 {"c", 4},
91 {"d", 6},
92 {"e", 8}};
93
94 // Time: 0 1 2 3 4 5 6 7 8 9 10
95 // Sent: a b c d e |
96 // Recv: b |
97 // Wind: --------------> |
98 TEST_F(PacketLossEstimatorTest, Lost3_Received1_Waiting1) {
99 PacketLossEstimator ple(3, 100);
100
101 for (const auto& p : kFivePackets) {
102 ple.ExpectResponse(p.first, p.second);
103 }
104 ple.ReceivedResponse("b", 3);
105 ple.UpdateResponseRate(10);
106 EXPECT_EQ(0.25, ple.get_response_rate());
107 }
108
109 // Time: 0 1 2 3 4 5 6 7 8 9 10
110 // Sent: a b c d e |
111 // Recv: e |
112 // Wind: --------------> |
113 TEST_F(PacketLossEstimatorTest, Lost4_Early1) {
114 PacketLossEstimator ple(3, 100);
115
116 for (const auto& p : kFivePackets) {
117 ple.ExpectResponse(p.first, p.second);
118 }
119 ple.ReceivedResponse("e", 9);
120 ple.UpdateResponseRate(10);
121 // e should be considered, even though its response was received less than
122 // |consider_lost_after_ms| ago.
123 EXPECT_EQ(0.2, ple.get_response_rate());
124 }
125
126 // Time: 0 1 2 3 4 5 6 7 8 9 10
127 // Sent: a b c d e |
128 // Recv: c |
129 // Wind: <-------> |
130 TEST_F(PacketLossEstimatorTest, Forgot2_Received1_Lost1_Waiting1) {
131 PacketLossEstimator ple(3, 7);
132
133 for (const auto& p : kFivePackets) {
134 ple.ExpectResponse(p.first, p.second);
135 }
136 ple.ReceivedResponse("c", 5);
137 ple.UpdateResponseRate(10);
138 EXPECT_EQ(0.5, ple.get_response_rate());
139 }
140
141 // Tests that old messages are forgotten if ExpectResponse is called
142 // |forget_after_ms| after |last_forgot_at|. It is important that ExpectResponse
143 // and ReceivedResponse forget old messages to avoid |tracked_packets_| growing
144 // without bound if UpdateResponseRate is never called (or rarely called).
145 //
146 // Time: 0 1 2 3 4 5 6
147 // Sent: a b
148 // Wind: <------->
149 TEST_F(PacketLossEstimatorTest, ExpectResponseForgetsOldPackets) {
150 PacketLossEstimator ple(1, 5);
151 ple.ExpectResponse("a", 0); // This message will be forgotten.
152 ple.ExpectResponse("b", 6); // This call should trigger clean up.
153 // a should be forgotten, b should be tracked.
154 EXPECT_EQ(1u, ple.tracked_packet_count_for_testing());
155 }
156
157 // Tests that old messages are forgotten if ExpectResponse is called
158 // |forget_after_ms| after |last_forgot_at|. It is important that ExpectResponse
159 // and ReceivedResponse forget old messages to avoid |tracked_packets_| growing
160 // without bound if UpdateResponseRate is never called (or rarely called).
161 //
162 // Time: 0 1 2 3 4 5 6
163 // Sent: a
164 // Recv: b
165 // Wind: <------->
166 TEST_F(PacketLossEstimatorTest, ReceivedResponseForgetsOldPackets) {
167 PacketLossEstimator ple(1, 5);
168 ple.ExpectResponse("a", 0); // This message will be forgotten.
169 ple.ReceivedResponse("b", 6); // This call should trigger clean up.
170 // a should be forgoten, b should not be tracked (received but not sent).
171 EXPECT_EQ(0u, ple.tracked_packet_count_for_testing());
172 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/packetlossestimator.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698