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

Side by Side Diff: webrtc/test/fake_network_pipe_unittest.cc

Issue 1512853002: Nuke TickTime::UseFakeClock. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 5 years 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/test/fake_network_pipe.cc ('k') | webrtc/video_engine/call_stats.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 #include "webrtc/base/scoped_ptr.h" 14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/call.h" 15 #include "webrtc/call.h"
16 #include "webrtc/system_wrappers/include/tick_util.h" 16 #include "webrtc/system_wrappers/include/clock.h"
17 #include "webrtc/test/fake_network_pipe.h" 17 #include "webrtc/test/fake_network_pipe.h"
18 18
19 using ::testing::_; 19 using ::testing::_;
20 using ::testing::AnyNumber; 20 using ::testing::AnyNumber;
21 using ::testing::Return; 21 using ::testing::Return;
22 using ::testing::Invoke; 22 using ::testing::Invoke;
23 23
24 namespace webrtc { 24 namespace webrtc {
25 25
26 class MockReceiver : public PacketReceiver { 26 class MockReceiver : public PacketReceiver {
27 public: 27 public:
28 MockReceiver() {} 28 MockReceiver() {}
29 virtual ~MockReceiver() {} 29 virtual ~MockReceiver() {}
30 30
31 void IncomingPacket(const uint8_t* data, size_t length) { 31 void IncomingPacket(const uint8_t* data, size_t length) {
32 DeliverPacket(MediaType::ANY, data, length, PacketTime()); 32 DeliverPacket(MediaType::ANY, data, length, PacketTime());
33 delete [] data; 33 delete [] data;
34 } 34 }
35 35
36 MOCK_METHOD4( 36 MOCK_METHOD4(
37 DeliverPacket, 37 DeliverPacket,
38 DeliveryStatus(MediaType, const uint8_t*, size_t, const PacketTime&)); 38 DeliveryStatus(MediaType, const uint8_t*, size_t, const PacketTime&));
39 }; 39 };
40 40
41 class FakeNetworkPipeTest : public ::testing::Test { 41 class FakeNetworkPipeTest : public ::testing::Test {
42 public:
43 FakeNetworkPipeTest() : fake_clock_(12345) {}
44
42 protected: 45 protected:
43 virtual void SetUp() { 46 virtual void SetUp() {
44 TickTime::UseFakeClock(12345);
45 receiver_.reset(new MockReceiver()); 47 receiver_.reset(new MockReceiver());
46 ON_CALL(*receiver_, DeliverPacket(_, _, _, _)) 48 ON_CALL(*receiver_, DeliverPacket(_, _, _, _))
47 .WillByDefault(Return(PacketReceiver::DELIVERY_OK)); 49 .WillByDefault(Return(PacketReceiver::DELIVERY_OK));
48 } 50 }
49 51
50 virtual void TearDown() { 52 virtual void TearDown() {
51 } 53 }
52 54
53 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int kPacketSize) { 55 void SendPackets(FakeNetworkPipe* pipe, int number_packets, int kPacketSize) {
54 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[kPacketSize]); 56 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[kPacketSize]);
55 for (int i = 0; i < number_packets; ++i) { 57 for (int i = 0; i < number_packets; ++i) {
56 pipe->SendPacket(packet.get(), kPacketSize); 58 pipe->SendPacket(packet.get(), kPacketSize);
57 } 59 }
58 } 60 }
59 61
60 int PacketTimeMs(int capacity_kbps, int kPacketSize) const { 62 int PacketTimeMs(int capacity_kbps, int kPacketSize) const {
61 return 8 * kPacketSize / capacity_kbps; 63 return 8 * kPacketSize / capacity_kbps;
62 } 64 }
63 65
66 SimulatedClock fake_clock_;
64 rtc::scoped_ptr<MockReceiver> receiver_; 67 rtc::scoped_ptr<MockReceiver> receiver_;
65 }; 68 };
66 69
67 void DeleteMemory(uint8_t* data, int length) { delete [] data; } 70 void DeleteMemory(uint8_t* data, int length) { delete [] data; }
68 71
69 // Test the capacity link and verify we get as many packets as we expect. 72 // Test the capacity link and verify we get as many packets as we expect.
70 TEST_F(FakeNetworkPipeTest, CapacityTest) { 73 TEST_F(FakeNetworkPipeTest, CapacityTest) {
71 FakeNetworkPipe::Config config; 74 FakeNetworkPipe::Config config;
72 config.queue_length_packets = 20; 75 config.queue_length_packets = 20;
73 config.link_capacity_kbps = 80; 76 config.link_capacity_kbps = 80;
74 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 77 rtc::scoped_ptr<FakeNetworkPipe> pipe(
78 new FakeNetworkPipe(&fake_clock_, config));
75 pipe->SetReceiver(receiver_.get()); 79 pipe->SetReceiver(receiver_.get());
76 80
77 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to 81 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to
78 // get through the pipe. 82 // get through the pipe.
79 const int kNumPackets = 10; 83 const int kNumPackets = 10;
80 const int kPacketSize = 1000; 84 const int kPacketSize = 1000;
81 SendPackets(pipe.get(), kNumPackets , kPacketSize); 85 SendPackets(pipe.get(), kNumPackets , kPacketSize);
82 86
83 // Time to get one packet through the link. 87 // Time to get one packet through the link.
84 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 88 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
85 kPacketSize); 89 kPacketSize);
86 90
87 // Time haven't increased yet, so we souldn't get any packets. 91 // Time haven't increased yet, so we souldn't get any packets.
88 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 92 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
89 pipe->Process(); 93 pipe->Process();
90 94
91 // Advance enough time to release one packet. 95 // Advance enough time to release one packet.
92 TickTime::AdvanceFakeClock(kPacketTimeMs); 96 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs);
93 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 97 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
94 pipe->Process(); 98 pipe->Process();
95 99
96 // Release all but one packet 100 // Release all but one packet
97 TickTime::AdvanceFakeClock(9 * kPacketTimeMs - 1); 101 fake_clock_.AdvanceTimeMilliseconds(9 * kPacketTimeMs - 1);
98 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(8); 102 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(8);
99 pipe->Process(); 103 pipe->Process();
100 104
101 // And the last one. 105 // And the last one.
102 TickTime::AdvanceFakeClock(1); 106 fake_clock_.AdvanceTimeMilliseconds(1);
103 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 107 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
104 pipe->Process(); 108 pipe->Process();
105 } 109 }
106 110
107 // Test the extra network delay. 111 // Test the extra network delay.
108 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { 112 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) {
109 FakeNetworkPipe::Config config; 113 FakeNetworkPipe::Config config;
110 config.queue_length_packets = 20; 114 config.queue_length_packets = 20;
111 config.queue_delay_ms = 100; 115 config.queue_delay_ms = 100;
112 config.link_capacity_kbps = 80; 116 config.link_capacity_kbps = 80;
113 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 117 rtc::scoped_ptr<FakeNetworkPipe> pipe(
118 new FakeNetworkPipe(&fake_clock_, config));
114 pipe->SetReceiver(receiver_.get()); 119 pipe->SetReceiver(receiver_.get());
115 120
116 const int kNumPackets = 2; 121 const int kNumPackets = 2;
117 const int kPacketSize = 1000; 122 const int kPacketSize = 1000;
118 SendPackets(pipe.get(), kNumPackets , kPacketSize); 123 SendPackets(pipe.get(), kNumPackets , kPacketSize);
119 124
120 // Time to get one packet through the link. 125 // Time to get one packet through the link.
121 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 126 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
122 kPacketSize); 127 kPacketSize);
123 128
124 // Increase more than kPacketTimeMs, but not more than the extra delay. 129 // Increase more than kPacketTimeMs, but not more than the extra delay.
125 TickTime::AdvanceFakeClock(kPacketTimeMs); 130 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs);
126 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 131 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
127 pipe->Process(); 132 pipe->Process();
128 133
129 // Advance the network delay to get the first packet. 134 // Advance the network delay to get the first packet.
130 TickTime::AdvanceFakeClock(config.queue_delay_ms); 135 fake_clock_.AdvanceTimeMilliseconds(config.queue_delay_ms);
131 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 136 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
132 pipe->Process(); 137 pipe->Process();
133 138
134 // Advance one more kPacketTimeMs to get the last packet. 139 // Advance one more kPacketTimeMs to get the last packet.
135 TickTime::AdvanceFakeClock(kPacketTimeMs); 140 fake_clock_.AdvanceTimeMilliseconds(kPacketTimeMs);
136 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 141 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
137 pipe->Process(); 142 pipe->Process();
138 } 143 }
139 144
140 // Test the number of buffers and packets are dropped when sending too many 145 // Test the number of buffers and packets are dropped when sending too many
141 // packets too quickly. 146 // packets too quickly.
142 TEST_F(FakeNetworkPipeTest, QueueLengthTest) { 147 TEST_F(FakeNetworkPipeTest, QueueLengthTest) {
143 FakeNetworkPipe::Config config; 148 FakeNetworkPipe::Config config;
144 config.queue_length_packets = 2; 149 config.queue_length_packets = 2;
145 config.link_capacity_kbps = 80; 150 config.link_capacity_kbps = 80;
146 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 151 rtc::scoped_ptr<FakeNetworkPipe> pipe(
152 new FakeNetworkPipe(&fake_clock_, config));
147 pipe->SetReceiver(receiver_.get()); 153 pipe->SetReceiver(receiver_.get());
148 154
149 const int kPacketSize = 1000; 155 const int kPacketSize = 1000;
150 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 156 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
151 kPacketSize); 157 kPacketSize);
152 158
153 // Send three packets and verify only 2 are delivered. 159 // Send three packets and verify only 2 are delivered.
154 SendPackets(pipe.get(), 3, kPacketSize); 160 SendPackets(pipe.get(), 3, kPacketSize);
155 161
156 // Increase time enough to deliver all three packets, verify only two are 162 // Increase time enough to deliver all three packets, verify only two are
157 // delivered. 163 // delivered.
158 TickTime::AdvanceFakeClock(3 * kPacketTimeMs); 164 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs);
159 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); 165 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2);
160 pipe->Process(); 166 pipe->Process();
161 } 167 }
162 168
163 // Test we get statistics as expected. 169 // Test we get statistics as expected.
164 TEST_F(FakeNetworkPipeTest, StatisticsTest) { 170 TEST_F(FakeNetworkPipeTest, StatisticsTest) {
165 FakeNetworkPipe::Config config; 171 FakeNetworkPipe::Config config;
166 config.queue_length_packets = 2; 172 config.queue_length_packets = 2;
167 config.queue_delay_ms = 20; 173 config.queue_delay_ms = 20;
168 config.link_capacity_kbps = 80; 174 config.link_capacity_kbps = 80;
169 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 175 rtc::scoped_ptr<FakeNetworkPipe> pipe(
176 new FakeNetworkPipe(&fake_clock_, config));
170 pipe->SetReceiver(receiver_.get()); 177 pipe->SetReceiver(receiver_.get());
171 178
172 const int kPacketSize = 1000; 179 const int kPacketSize = 1000;
173 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps, 180 const int kPacketTimeMs = PacketTimeMs(config.link_capacity_kbps,
174 kPacketSize); 181 kPacketSize);
175 182
176 // Send three packets and verify only 2 are delivered. 183 // Send three packets and verify only 2 are delivered.
177 SendPackets(pipe.get(), 3, kPacketSize); 184 SendPackets(pipe.get(), 3, kPacketSize);
178 TickTime::AdvanceFakeClock(3 * kPacketTimeMs + config.queue_delay_ms); 185 fake_clock_.AdvanceTimeMilliseconds(3 * kPacketTimeMs +
186 config.queue_delay_ms);
179 187
180 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2); 188 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(2);
181 pipe->Process(); 189 pipe->Process();
182 190
183 // Packet 1: kPacketTimeMs + config.queue_delay_ms, 191 // Packet 1: kPacketTimeMs + config.queue_delay_ms,
184 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average. 192 // packet 2: 2 * kPacketTimeMs + config.queue_delay_ms => 170 ms average.
185 EXPECT_EQ(pipe->AverageDelay(), 170); 193 EXPECT_EQ(pipe->AverageDelay(), 170);
186 EXPECT_EQ(pipe->sent_packets(), 2u); 194 EXPECT_EQ(pipe->sent_packets(), 2u);
187 EXPECT_EQ(pipe->dropped_packets(), 1u); 195 EXPECT_EQ(pipe->dropped_packets(), 1u);
188 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f); 196 EXPECT_EQ(pipe->PercentageLoss(), 1/3.f);
189 } 197 }
190 198
191 // Change the link capacity half-way through the test and verify that the 199 // Change the link capacity half-way through the test and verify that the
192 // delivery times change accordingly. 200 // delivery times change accordingly.
193 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { 201 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) {
194 FakeNetworkPipe::Config config; 202 FakeNetworkPipe::Config config;
195 config.queue_length_packets = 20; 203 config.queue_length_packets = 20;
196 config.link_capacity_kbps = 80; 204 config.link_capacity_kbps = 80;
197 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 205 rtc::scoped_ptr<FakeNetworkPipe> pipe(
206 new FakeNetworkPipe(&fake_clock_, config));
198 pipe->SetReceiver(receiver_.get()); 207 pipe->SetReceiver(receiver_.get());
199 208
200 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to 209 // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to
201 // get through the pipe. 210 // get through the pipe.
202 const int kNumPackets = 10; 211 const int kNumPackets = 10;
203 const int kPacketSize = 1000; 212 const int kPacketSize = 1000;
204 SendPackets(pipe.get(), kNumPackets, kPacketSize); 213 SendPackets(pipe.get(), kNumPackets, kPacketSize);
205 214
206 // Time to get one packet through the link. 215 // Time to get one packet through the link.
207 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 216 int packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
208 217
209 // Time hasn't increased yet, so we souldn't get any packets. 218 // Time hasn't increased yet, so we souldn't get any packets.
210 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 219 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
211 pipe->Process(); 220 pipe->Process();
212 221
213 // Advance time in steps to release one packet at a time. 222 // Advance time in steps to release one packet at a time.
214 for (int i = 0; i < kNumPackets; ++i) { 223 for (int i = 0; i < kNumPackets; ++i) {
215 TickTime::AdvanceFakeClock(packet_time_ms); 224 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms);
216 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 225 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
217 pipe->Process(); 226 pipe->Process();
218 } 227 }
219 228
220 // Change the capacity. 229 // Change the capacity.
221 config.link_capacity_kbps /= 2; // Reduce to 50%. 230 config.link_capacity_kbps /= 2; // Reduce to 50%.
222 pipe->SetConfig(config); 231 pipe->SetConfig(config);
223 232
224 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two 233 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two
225 // seconds to get them through the pipe. 234 // seconds to get them through the pipe.
226 SendPackets(pipe.get(), kNumPackets, kPacketSize); 235 SendPackets(pipe.get(), kNumPackets, kPacketSize);
227 236
228 // Time to get one packet through the link. 237 // Time to get one packet through the link.
229 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 238 packet_time_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
230 239
231 // Time hasn't increased yet, so we souldn't get any packets. 240 // Time hasn't increased yet, so we souldn't get any packets.
232 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 241 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
233 pipe->Process(); 242 pipe->Process();
234 243
235 // Advance time in steps to release one packet at a time. 244 // Advance time in steps to release one packet at a time.
236 for (int i = 0; i < kNumPackets; ++i) { 245 for (int i = 0; i < kNumPackets; ++i) {
237 TickTime::AdvanceFakeClock(packet_time_ms); 246 fake_clock_.AdvanceTimeMilliseconds(packet_time_ms);
238 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 247 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
239 pipe->Process(); 248 pipe->Process();
240 } 249 }
241 250
242 // Check that all the packets were sent. 251 // Check that all the packets were sent.
243 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); 252 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets());
244 TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess()); 253 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess());
245 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 254 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
246 pipe->Process(); 255 pipe->Process();
247 } 256 }
248 257
249 // Change the link capacity half-way through the test and verify that the 258 // Change the link capacity half-way through the test and verify that the
250 // delivery times change accordingly. 259 // delivery times change accordingly.
251 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { 260 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) {
252 FakeNetworkPipe::Config config; 261 FakeNetworkPipe::Config config;
253 config.queue_length_packets = 20; 262 config.queue_length_packets = 20;
254 config.link_capacity_kbps = 80; 263 config.link_capacity_kbps = 80;
255 rtc::scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config)); 264 rtc::scoped_ptr<FakeNetworkPipe> pipe(
265 new FakeNetworkPipe(&fake_clock_, config));
256 pipe->SetReceiver(receiver_.get()); 266 pipe->SetReceiver(receiver_.get());
257 267
258 // Add 10 packets of 1000 bytes, = 80 kb. 268 // Add 10 packets of 1000 bytes, = 80 kb.
259 const int kNumPackets = 10; 269 const int kNumPackets = 10;
260 const int kPacketSize = 1000; 270 const int kPacketSize = 1000;
261 SendPackets(pipe.get(), kNumPackets, kPacketSize); 271 SendPackets(pipe.get(), kNumPackets, kPacketSize);
262 272
263 // Time to get one packet through the link at the initial speed. 273 // Time to get one packet through the link at the initial speed.
264 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 274 int packet_time_1_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
265 275
266 // Change the capacity. 276 // Change the capacity.
267 config.link_capacity_kbps *= 2; // Double the capacity. 277 config.link_capacity_kbps *= 2; // Double the capacity.
268 pipe->SetConfig(config); 278 pipe->SetConfig(config);
269 279
270 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two 280 // Add another 10 packets of 1000 bytes, = 80 kb, and verify it takes two
271 // seconds to get them through the pipe. 281 // seconds to get them through the pipe.
272 SendPackets(pipe.get(), kNumPackets, kPacketSize); 282 SendPackets(pipe.get(), kNumPackets, kPacketSize);
273 283
274 // Time to get one packet through the link at the new capacity. 284 // Time to get one packet through the link at the new capacity.
275 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize); 285 int packet_time_2_ms = PacketTimeMs(config.link_capacity_kbps, kPacketSize);
276 286
277 // Time hasn't increased yet, so we souldn't get any packets. 287 // Time hasn't increased yet, so we souldn't get any packets.
278 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 288 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
279 pipe->Process(); 289 pipe->Process();
280 290
281 // Advance time in steps to release one packet at a time. 291 // Advance time in steps to release one packet at a time.
282 for (int i = 0; i < kNumPackets; ++i) { 292 for (int i = 0; i < kNumPackets; ++i) {
283 TickTime::AdvanceFakeClock(packet_time_1_ms); 293 fake_clock_.AdvanceTimeMilliseconds(packet_time_1_ms);
284 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 294 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
285 pipe->Process(); 295 pipe->Process();
286 } 296 }
287 297
288 // Advance time in steps to release one packet at a time. 298 // Advance time in steps to release one packet at a time.
289 for (int i = 0; i < kNumPackets; ++i) { 299 for (int i = 0; i < kNumPackets; ++i) {
290 TickTime::AdvanceFakeClock(packet_time_2_ms); 300 fake_clock_.AdvanceTimeMilliseconds(packet_time_2_ms);
291 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1); 301 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(1);
292 pipe->Process(); 302 pipe->Process();
293 } 303 }
294 304
295 // Check that all the packets were sent. 305 // Check that all the packets were sent.
296 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets()); 306 EXPECT_EQ(static_cast<size_t>(2 * kNumPackets), pipe->sent_packets());
297 TickTime::AdvanceFakeClock(pipe->TimeUntilNextProcess()); 307 fake_clock_.AdvanceTimeMilliseconds(pipe->TimeUntilNextProcess());
298 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0); 308 EXPECT_CALL(*receiver_, DeliverPacket(_, _, _, _)).Times(0);
299 pipe->Process(); 309 pipe->Process();
300 } 310 }
301 } // namespace webrtc 311 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/fake_network_pipe.cc ('k') | webrtc/video_engine/call_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698