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 10 matching lines...) Expand all Loading... |
21 const QuicByteCount kBytesInFlight = 1024; | 21 const QuicByteCount kBytesInFlight = 1024; |
22 | 22 |
23 class PacingSenderTest : public ::testing::Test { | 23 class PacingSenderTest : public ::testing::Test { |
24 protected: | 24 protected: |
25 PacingSenderTest() | 25 PacingSenderTest() |
26 : zero_time_(QuicTime::Delta::Zero()), | 26 : zero_time_(QuicTime::Delta::Zero()), |
27 infinite_time_(QuicTime::Delta::Infinite()), | 27 infinite_time_(QuicTime::Delta::Infinite()), |
28 sequence_number_(1), | 28 sequence_number_(1), |
29 mock_sender_(new StrictMock<MockSendAlgorithm>()), | 29 mock_sender_(new StrictMock<MockSendAlgorithm>()), |
30 pacing_sender_(new PacingSender(mock_sender_, | 30 pacing_sender_(new PacingSender(mock_sender_, |
31 QuicTime::Delta::FromMilliseconds(1))) { | 31 QuicTime::Delta::FromMilliseconds(1), |
| 32 0)) { |
32 // Pick arbitrary time. | 33 // Pick arbitrary time. |
33 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); | 34 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); |
34 } | 35 } |
35 | 36 |
36 virtual ~PacingSenderTest() {} | 37 virtual ~PacingSenderTest() {} |
37 | 38 |
38 void CheckPacketIsSentImmediately() { | 39 void CheckPacketIsSentImmediately() { |
39 // In order for the packet to be sendable, the underlying sender must | 40 // In order for the packet to be sendable, the underlying sender must |
40 // permit it to be sent immediately. | 41 // permit it to be sent immediately. |
41 for (int i = 0; i < 2; ++i) { | 42 for (int i = 0; i < 2; ++i) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 197 |
197 // Wake up too early. | 198 // Wake up too early. |
198 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 199 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
199 | 200 |
200 // Wake up early, but after enough time has passed to permit a send. | 201 // Wake up early, but after enough time has passed to permit a send. |
201 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 202 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
202 CheckPacketIsSentImmediately(); | 203 CheckPacketIsSentImmediately(); |
203 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 204 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
204 } | 205 } |
205 | 206 |
| 207 TEST_F(PacingSenderTest, InitialBurst) { |
| 208 pacing_sender_.reset(); |
| 209 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
| 210 pacing_sender_.reset(new PacingSender(mock_sender_, |
| 211 QuicTime::Delta::FromMilliseconds(1), |
| 212 10)); |
| 213 |
| 214 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
| 215 // will be 1 packet per 1 ms. |
| 216 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
| 217 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 218 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
| 219 |
| 220 // Update the RTT and verify that the first 10 packets aren't paced. |
| 221 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 222 SendAlgorithmInterface::CongestionMap empty_map; |
| 223 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
| 224 |
| 225 // Send 10 packets, and verify that they are not paced. |
| 226 for (int i = 0 ; i < 10; ++i) { |
| 227 CheckPacketIsSentImmediately(); |
| 228 } |
| 229 |
| 230 CheckPacketIsSentImmediately(); |
| 231 CheckPacketIsSentImmediately(); |
| 232 CheckPacketIsSentImmediately(); |
| 233 |
| 234 // The first packet was a "make up", then we sent two packets "into the |
| 235 // future", so the delay should be 2. |
| 236 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 237 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 238 CheckPacketIsSentImmediately(); |
| 239 |
| 240 // Now reduce bytes in flight back to 0 by and ensure another burst of 10 can |
| 241 // be sent. |
| 242 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, 0, _, _)); |
| 243 pacing_sender_->OnCongestionEvent(true, 0, empty_map, empty_map); |
| 244 for (int i = 0 ; i < 10; ++i) { |
| 245 CheckPacketIsSentImmediately(); |
| 246 } |
| 247 |
| 248 CheckPacketIsSentImmediately(); |
| 249 CheckPacketIsSentImmediately(); |
| 250 CheckPacketIsSentImmediately(); |
| 251 |
| 252 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 253 } |
| 254 |
206 } // namespace test | 255 } // namespace test |
207 } // namespace net | 256 } // namespace net |
OLD | NEW |