OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/congestion_control/pacing_sender.h" | 5 #include "net/quic/congestion_control/pacing_sender.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "net/quic/quic_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
10 #include "net/quic/test_tools/mock_clock.h" | 10 #include "net/quic/test_tools/mock_clock.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 mock_sender_(new StrictMock<MockSendAlgorithm>()), | 30 mock_sender_(new StrictMock<MockSendAlgorithm>()), |
31 pacing_sender_(new PacingSender(mock_sender_, | 31 pacing_sender_(new PacingSender(mock_sender_, |
32 QuicTime::Delta::FromMilliseconds(1), | 32 QuicTime::Delta::FromMilliseconds(1), |
33 0)) { | 33 0)) { |
34 // Pick arbitrary time. | 34 // Pick arbitrary time. |
35 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); | 35 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); |
36 } | 36 } |
37 | 37 |
38 ~PacingSenderTest() override {} | 38 ~PacingSenderTest() override {} |
39 | 39 |
40 void CheckPacketIsSentImmediately() { | 40 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { |
| 41 pacing_sender_.reset(); |
| 42 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
| 43 pacing_sender_.reset(new PacingSender( |
| 44 mock_sender_, QuicTime::Delta::FromMilliseconds(1), burst_size)); |
| 45 EXPECT_CALL(*mock_sender_, PacingRate()).WillRepeatedly(Return(bandwidth)); |
| 46 } |
| 47 |
| 48 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, |
| 49 QuicByteCount bytes_in_flight) { |
41 // In order for the packet to be sendable, the underlying sender must | 50 // In order for the packet to be sendable, the underlying sender must |
42 // permit it to be sent immediately. | 51 // permit it to be sent immediately. |
43 for (int i = 0; i < 2; ++i) { | 52 for (int i = 0; i < 2; ++i) { |
44 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), | 53 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight, |
45 kBytesInFlight, | 54 retransmittable_data)) |
46 HAS_RETRANSMITTABLE_DATA)) | |
47 .WillOnce(Return(zero_time_)); | 55 .WillOnce(Return(zero_time_)); |
48 // Verify that the packet can be sent immediately. | 56 // Verify that the packet can be sent immediately. |
49 EXPECT_EQ(zero_time_, | 57 EXPECT_EQ(zero_time_, |
50 pacing_sender_->TimeUntilSend(clock_.Now(), | 58 pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight, |
51 kBytesInFlight, | 59 retransmittable_data)); |
52 HAS_RETRANSMITTABLE_DATA)); | |
53 } | 60 } |
54 | 61 |
55 // Actually send the packet. | 62 // Actually send the packet. |
56 EXPECT_CALL(*mock_sender_, | 63 EXPECT_CALL(*mock_sender_, |
57 OnPacketSent(clock_.Now(), kBytesInFlight, sequence_number_, | 64 OnPacketSent(clock_.Now(), bytes_in_flight, sequence_number_, |
58 kMaxPacketSize, HAS_RETRANSMITTABLE_DATA)); | 65 kMaxPacketSize, retransmittable_data)); |
59 pacing_sender_->OnPacketSent(clock_.Now(), kBytesInFlight, | 66 pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, |
60 sequence_number_++, kMaxPacketSize, | 67 sequence_number_++, kMaxPacketSize, |
61 HAS_RETRANSMITTABLE_DATA); | 68 retransmittable_data); |
| 69 } |
| 70 |
| 71 void CheckPacketIsSentImmediately() { |
| 72 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight); |
62 } | 73 } |
63 | 74 |
64 void CheckAckIsSentImmediately() { | 75 void CheckAckIsSentImmediately() { |
65 // In order for the ack to be sendable, the underlying sender must | 76 CheckPacketIsSentImmediately(NO_RETRANSMITTABLE_DATA, kBytesInFlight); |
66 // permit it to be sent immediately. | |
67 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), | |
68 0, | |
69 NO_RETRANSMITTABLE_DATA)) | |
70 .WillOnce(Return(zero_time_)); | |
71 // Verify that the ACK can be sent immediately. | |
72 EXPECT_EQ(zero_time_, | |
73 pacing_sender_->TimeUntilSend(clock_.Now(), | |
74 0, | |
75 NO_RETRANSMITTABLE_DATA)); | |
76 | |
77 // Actually send the packet. | |
78 EXPECT_CALL(*mock_sender_, | |
79 OnPacketSent(clock_.Now(), 0, sequence_number_, | |
80 kMaxPacketSize, NO_RETRANSMITTABLE_DATA)); | |
81 pacing_sender_->OnPacketSent(clock_.Now(), 0, | |
82 sequence_number_++, kMaxPacketSize, | |
83 NO_RETRANSMITTABLE_DATA); | |
84 } | 77 } |
85 | 78 |
86 void CheckPacketIsDelayed(QuicTime::Delta delay) { | 79 void CheckPacketIsDelayed(QuicTime::Delta delay) { |
87 // In order for the packet to be sendable, the underlying sender must | 80 // In order for the packet to be sendable, the underlying sender must |
88 // permit it to be sent immediately. | 81 // permit it to be sent immediately. |
89 for (int i = 0; i < 2; ++i) { | 82 for (int i = 0; i < 2; ++i) { |
90 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), | 83 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), |
91 kBytesInFlight, | 84 kBytesInFlight, |
92 HAS_RETRANSMITTABLE_DATA)) | 85 HAS_RETRANSMITTABLE_DATA)) |
93 .WillOnce(Return(zero_time_)); | 86 .WillOnce(Return(zero_time_)); |
94 // Verify that the packet is delayed. | 87 // Verify that the packet is delayed. |
95 EXPECT_EQ(delay.ToMicroseconds(), | 88 EXPECT_EQ(delay.ToMicroseconds(), |
96 pacing_sender_->TimeUntilSend( | 89 pacing_sender_->TimeUntilSend( |
97 clock_.Now(), kBytesInFlight, | 90 clock_.Now(), kBytesInFlight, |
98 HAS_RETRANSMITTABLE_DATA).ToMicroseconds()); | 91 HAS_RETRANSMITTABLE_DATA).ToMicroseconds()); |
99 } | 92 } |
100 } | 93 } |
101 | 94 |
| 95 void UpdateRtt() { |
| 96 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 97 SendAlgorithmInterface::CongestionVector empty_map; |
| 98 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, |
| 99 empty_map); |
| 100 } |
| 101 |
102 const QuicTime::Delta zero_time_; | 102 const QuicTime::Delta zero_time_; |
103 const QuicTime::Delta infinite_time_; | 103 const QuicTime::Delta infinite_time_; |
104 MockClock clock_; | 104 MockClock clock_; |
105 QuicPacketSequenceNumber sequence_number_; | 105 QuicPacketSequenceNumber sequence_number_; |
106 StrictMock<MockSendAlgorithm>* mock_sender_; | 106 StrictMock<MockSendAlgorithm>* mock_sender_; |
107 scoped_ptr<PacingSender> pacing_sender_; | 107 scoped_ptr<PacingSender> pacing_sender_; |
108 }; | 108 }; |
109 | 109 |
110 TEST_F(PacingSenderTest, NoSend) { | 110 TEST_F(PacingSenderTest, NoSend) { |
111 for (int i = 0; i < 2; ++i) { | 111 for (int i = 0; i < 2; ++i) { |
(...skipping 15 matching lines...) Expand all Loading... |
127 HAS_RETRANSMITTABLE_DATA)) | 127 HAS_RETRANSMITTABLE_DATA)) |
128 .WillOnce(Return(zero_time_)); | 128 .WillOnce(Return(zero_time_)); |
129 EXPECT_EQ(zero_time_, | 129 EXPECT_EQ(zero_time_, |
130 pacing_sender_->TimeUntilSend(clock_.Now(), | 130 pacing_sender_->TimeUntilSend(clock_.Now(), |
131 kBytesInFlight, | 131 kBytesInFlight, |
132 HAS_RETRANSMITTABLE_DATA)); | 132 HAS_RETRANSMITTABLE_DATA)); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 TEST_F(PacingSenderTest, VariousSending) { | 136 TEST_F(PacingSenderTest, VariousSending) { |
137 // Configure pacing rate of 1 packet per 1 ms. | 137 // Configure pacing rate of 1 packet per 1 ms, no initial burst. |
138 EXPECT_CALL(*mock_sender_, PacingRate()) | 138 InitPacingRate(0, QuicBandwidth::FromBytesAndTimeDelta( |
139 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 139 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
140 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); | |
141 | 140 |
142 // Now update the RTT and verify that packets are actually paced. | 141 // Now update the RTT and verify that packets are actually paced. |
143 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 142 UpdateRtt(); |
144 SendAlgorithmInterface::CongestionVector empty_map; | |
145 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | |
146 | 143 |
147 CheckPacketIsSentImmediately(); | 144 CheckPacketIsSentImmediately(); |
148 CheckPacketIsSentImmediately(); | 145 CheckPacketIsSentImmediately(); |
149 CheckPacketIsSentImmediately(); | |
150 | 146 |
151 // The first packet was a "make up", then we sent two packets "into the | 147 // The first packet was a "make up", then we sent two packets "into the |
152 // future", so the delay should be 2. | 148 // future", so the delay should be 2. |
153 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 149 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
154 | 150 |
155 // Wake up on time. | 151 // Wake up on time. |
156 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); | 152 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); |
157 CheckPacketIsSentImmediately(); | 153 CheckPacketIsSentImmediately(); |
158 CheckPacketIsSentImmediately(); | 154 CheckPacketIsSentImmediately(); |
159 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 155 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
(...skipping 20 matching lines...) Expand all Loading... |
180 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 176 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
181 | 177 |
182 // Wake up really late again, but application pause partway through. | 178 // Wake up really late again, but application pause partway through. |
183 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8)); | 179 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8)); |
184 CheckPacketIsSentImmediately(); | 180 CheckPacketIsSentImmediately(); |
185 CheckPacketIsSentImmediately(); | 181 CheckPacketIsSentImmediately(); |
186 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); | 182 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); |
187 CheckPacketIsSentImmediately(); | 183 CheckPacketIsSentImmediately(); |
188 CheckPacketIsSentImmediately(); | 184 CheckPacketIsSentImmediately(); |
189 CheckPacketIsSentImmediately(); | 185 CheckPacketIsSentImmediately(); |
190 CheckPacketIsSentImmediately(); | |
191 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 186 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
192 | 187 |
193 // Wake up too early. | 188 // Wake up too early. |
194 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 189 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
195 | 190 |
196 // Wake up early, but after enough time has passed to permit a send. | 191 // Wake up early, but after enough time has passed to permit a send. |
197 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 192 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
198 CheckPacketIsSentImmediately(); | 193 CheckPacketIsSentImmediately(); |
199 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 194 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
200 } | 195 } |
201 | 196 |
202 TEST_F(PacingSenderTest, CongestionAvoidanceSending) { | 197 // TODO(ianswett): Remove this test. |
| 198 TEST_F(PacingSenderTest, DISABLED_CongestionAvoidanceSending) { |
203 // Configure pacing rate of 1 packet per 1 ms. | 199 // Configure pacing rate of 1 packet per 1 ms. |
204 EXPECT_CALL(*mock_sender_, PacingRate()) | 200 EXPECT_CALL(*mock_sender_, PacingRate()) |
205 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 201 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
206 kMaxPacketSize * 1.25, QuicTime::Delta::FromMilliseconds(2)))); | 202 kMaxPacketSize * 1.25, QuicTime::Delta::FromMilliseconds(2)))); |
207 | 203 |
208 // Now update the RTT and verify that packets are actually paced. | 204 // Now update the RTT and verify that packets are actually paced. |
209 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 205 UpdateRtt(); |
210 SendAlgorithmInterface::CongestionVector empty_map; | |
211 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | |
212 | 206 |
213 CheckPacketIsSentImmediately(); | 207 CheckPacketIsSentImmediately(); |
214 CheckPacketIsSentImmediately(); | 208 CheckPacketIsSentImmediately(); |
215 | 209 |
216 // The first packet was a "make up", then we sent two packets "into the | 210 // The first packet was a "make up", then we sent two packets "into the |
217 // future", so the delay should be 2200us. | 211 // future", so the delay should be 2200us. |
218 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); | 212 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); |
219 | 213 |
220 // Wake up on time. | 214 // Wake up on time. |
221 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(2200)); | 215 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(2200)); |
(...skipping 30 matching lines...) Expand all Loading... |
252 // Wake up too early. | 246 // Wake up too early. |
253 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); | 247 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2200)); |
254 | 248 |
255 // Wake up early, but after enough time has passed to permit a send. | 249 // Wake up early, but after enough time has passed to permit a send. |
256 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1200)); | 250 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1200)); |
257 CheckPacketIsSentImmediately(); | 251 CheckPacketIsSentImmediately(); |
258 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2600)); | 252 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2600)); |
259 } | 253 } |
260 | 254 |
261 TEST_F(PacingSenderTest, InitialBurst) { | 255 TEST_F(PacingSenderTest, InitialBurst) { |
262 pacing_sender_.reset(); | |
263 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | |
264 pacing_sender_.reset(new PacingSender(mock_sender_, | |
265 QuicTime::Delta::FromMilliseconds(1), | |
266 10)); | |
267 | |
268 // Configure pacing rate of 1 packet per 1 ms. | 256 // Configure pacing rate of 1 packet per 1 ms. |
269 EXPECT_CALL(*mock_sender_, PacingRate()) | 257 InitPacingRate(10, QuicBandwidth::FromBytesAndTimeDelta( |
270 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 258 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
271 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); | |
272 | 259 |
273 // Update the RTT and verify that the first 10 packets aren't paced. | 260 // Update the RTT and verify that the first 10 packets aren't paced. |
274 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 261 UpdateRtt(); |
275 SendAlgorithmInterface::CongestionVector empty_map; | |
276 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | |
277 | 262 |
278 // Send 10 packets, and verify that they are not paced. | 263 // Send 10 packets, and verify that they are not paced. |
279 for (int i = 0 ; i < kInitialBurstPackets; ++i) { | 264 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
280 CheckPacketIsSentImmediately(); | 265 CheckPacketIsSentImmediately(); |
281 } | 266 } |
282 | 267 |
283 // The first packet was a "make up", then we sent two packets "into the | 268 // The first packet was a "make up", then we sent two packets "into the |
284 // future", so the delay should be 2ms. | 269 // future", so the delay should be 2ms. |
285 CheckPacketIsSentImmediately(); | 270 CheckPacketIsSentImmediately(); |
286 CheckPacketIsSentImmediately(); | 271 CheckPacketIsSentImmediately(); |
287 CheckPacketIsSentImmediately(); | |
288 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 272 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
289 | 273 |
290 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 274 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
291 CheckPacketIsSentImmediately(); | 275 CheckPacketIsSentImmediately(); |
292 | 276 |
293 // Next time TimeUntilSend is called with no bytes in flight, the tokens | 277 // Next time TimeUntilSend is called with no bytes in flight, pacing should |
294 // should be refilled and there should be no delay. | 278 // allow a packet to be sent, and when it's sent, the tokens are refilled. |
295 EXPECT_CALL(*mock_sender_, | 279 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); |
296 TimeUntilSend(clock_.Now(), | 280 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
297 0, | |
298 HAS_RETRANSMITTABLE_DATA)). | |
299 WillOnce(Return(zero_time_)); | |
300 EXPECT_EQ(zero_time_, | |
301 pacing_sender_->TimeUntilSend(clock_.Now(), | |
302 0, | |
303 HAS_RETRANSMITTABLE_DATA)); | |
304 for (int i = 0 ; i < kInitialBurstPackets; ++i) { | |
305 CheckPacketIsSentImmediately(); | 281 CheckPacketIsSentImmediately(); |
306 } | 282 } |
307 | 283 |
308 // The first packet was a "make up", then we sent two packets "into the | 284 // The first packet was a "make up", then we sent two packets "into the |
309 // future", so the delay should be 2ms. | 285 // future", so the delay should be 2ms. |
310 CheckPacketIsSentImmediately(); | 286 CheckPacketIsSentImmediately(); |
311 CheckPacketIsSentImmediately(); | 287 CheckPacketIsSentImmediately(); |
312 CheckPacketIsSentImmediately(); | |
313 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 288 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
314 } | 289 } |
315 | 290 |
316 TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { | 291 TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
317 pacing_sender_.reset(); | |
318 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | |
319 pacing_sender_.reset(new PacingSender(mock_sender_, | |
320 QuicTime::Delta::FromMilliseconds(1), | |
321 10)); | |
322 | |
323 // Configure pacing rate of 1 packet per 1 ms. | 292 // Configure pacing rate of 1 packet per 1 ms. |
324 EXPECT_CALL(*mock_sender_, PacingRate()) | 293 InitPacingRate(10, QuicBandwidth::FromBytesAndTimeDelta( |
325 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 294 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
326 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); | |
327 | 295 |
328 // Send 10 packets, and verify that they are not paced. | 296 // Send 10 packets, and verify that they are not paced. |
329 for (int i = 0 ; i < kInitialBurstPackets; ++i) { | 297 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
330 CheckPacketIsSentImmediately(); | 298 CheckPacketIsSentImmediately(); |
331 } | 299 } |
332 | 300 |
333 // The first packet was a "make up", then we sent two packets "into the | 301 // The first packet was a "make up", then we sent two packets "into the |
334 // future", so the delay should be 2ms. | 302 // future", so the delay should be 2ms. |
335 CheckPacketIsSentImmediately(); | 303 CheckPacketIsSentImmediately(); |
336 CheckPacketIsSentImmediately(); | 304 CheckPacketIsSentImmediately(); |
337 CheckPacketIsSentImmediately(); | |
338 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 305 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
339 | 306 |
340 | 307 |
341 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 308 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
342 CheckPacketIsSentImmediately(); | 309 CheckPacketIsSentImmediately(); |
343 | 310 |
344 // Next time TimeUntilSend is called with no bytes in flight, the tokens | 311 // Next time TimeUntilSend is called with no bytes in flight, the tokens |
345 // should be refilled and there should be no delay. | 312 // should be refilled and there should be no delay. |
346 EXPECT_CALL(*mock_sender_, | 313 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); |
347 TimeUntilSend(clock_.Now(), | |
348 0, | |
349 HAS_RETRANSMITTABLE_DATA)). | |
350 WillOnce(Return(zero_time_)); | |
351 EXPECT_EQ(zero_time_, | |
352 pacing_sender_->TimeUntilSend(clock_.Now(), | |
353 0, | |
354 HAS_RETRANSMITTABLE_DATA)); | |
355 // Send 10 packets, and verify that they are not paced. | 314 // Send 10 packets, and verify that they are not paced. |
356 for (int i = 0 ; i < kInitialBurstPackets; ++i) { | 315 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
357 CheckPacketIsSentImmediately(); | 316 CheckPacketIsSentImmediately(); |
358 } | 317 } |
359 | 318 |
360 // The first packet was a "make up", then we sent two packets "into the | 319 // The first packet was a "make up", then we sent two packets "into the |
361 // future", so the delay should be 2ms. | 320 // future", so the delay should be 2ms. |
362 CheckPacketIsSentImmediately(); | 321 CheckPacketIsSentImmediately(); |
363 CheckPacketIsSentImmediately(); | 322 CheckPacketIsSentImmediately(); |
364 CheckPacketIsSentImmediately(); | |
365 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 323 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
366 } | 324 } |
367 | 325 |
| 326 TEST_F(PacingSenderTest, FastSending) { |
| 327 // Ensure the pacing sender paces, even when the inter-packet spacing is less |
| 328 // than the pacing granularity. |
| 329 InitPacingRate(10, |
| 330 QuicBandwidth::FromBytesAndTimeDelta( |
| 331 2 * kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
| 332 |
| 333 // Update the RTT and verify that the first 10 packets aren't paced. |
| 334 UpdateRtt(); |
| 335 |
| 336 // Send 10 packets, and verify that they are not paced. |
| 337 for (int i = 0; i < kInitialBurstPackets; ++i) { |
| 338 CheckPacketIsSentImmediately(); |
| 339 } |
| 340 |
| 341 // The first packet was a "make up", then we sent two packets "into the |
| 342 // future", since it's 2 packets/ms, so the delay should be 1.5ms. |
| 343 CheckPacketIsSentImmediately(); |
| 344 CheckPacketIsSentImmediately(); |
| 345 CheckPacketIsSentImmediately(); |
| 346 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); |
| 347 |
| 348 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 349 CheckPacketIsSentImmediately(); |
| 350 |
| 351 // Next time TimeUntilSend is called with no bytes in flight, the tokens |
| 352 // should be refilled and there should be no delay. |
| 353 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); |
| 354 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 355 CheckPacketIsSentImmediately(); |
| 356 } |
| 357 |
| 358 // The first packet was a "make up", then we sent two packets "into the |
| 359 // future", so the delay should be 1.5ms. |
| 360 CheckPacketIsSentImmediately(); |
| 361 CheckPacketIsSentImmediately(); |
| 362 CheckPacketIsSentImmediately(); |
| 363 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); |
| 364 } |
| 365 |
368 } // namespace test | 366 } // namespace test |
369 } // namespace net | 367 } // namespace net |
OLD | NEW |