Index: net/quic/congestion_control/pacing_sender_test.cc |
diff --git a/net/quic/congestion_control/pacing_sender_test.cc b/net/quic/congestion_control/pacing_sender_test.cc |
index a7838b91eb0302a4c91e8d0e6c8335a38c002e01..3c240e277bbb16aca29f74191912c301008172ec 100644 |
--- a/net/quic/congestion_control/pacing_sender_test.cc |
+++ b/net/quic/congestion_control/pacing_sender_test.cc |
@@ -37,50 +37,43 @@ class PacingSenderTest : public ::testing::Test { |
~PacingSenderTest() override {} |
- void CheckPacketIsSentImmediately() { |
+ void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { |
+ pacing_sender_.reset(); |
+ mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
+ pacing_sender_.reset(new PacingSender( |
+ mock_sender_, QuicTime::Delta::FromMilliseconds(1), burst_size)); |
+ EXPECT_CALL(*mock_sender_, PacingRate()).WillRepeatedly(Return(bandwidth)); |
+ } |
+ |
+ void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, |
+ QuicByteCount bytes_in_flight) { |
// In order for the packet to be sendable, the underlying sender must |
// permit it to be sent immediately. |
for (int i = 0; i < 2; ++i) { |
- EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), |
- kBytesInFlight, |
- HAS_RETRANSMITTABLE_DATA)) |
+ EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight, |
+ retransmittable_data)) |
.WillOnce(Return(zero_time_)); |
// Verify that the packet can be sent immediately. |
EXPECT_EQ(zero_time_, |
- pacing_sender_->TimeUntilSend(clock_.Now(), |
- kBytesInFlight, |
- HAS_RETRANSMITTABLE_DATA)); |
+ pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight, |
+ retransmittable_data)); |
} |
// Actually send the packet. |
EXPECT_CALL(*mock_sender_, |
- OnPacketSent(clock_.Now(), kBytesInFlight, sequence_number_, |
- kMaxPacketSize, HAS_RETRANSMITTABLE_DATA)); |
- pacing_sender_->OnPacketSent(clock_.Now(), kBytesInFlight, |
+ OnPacketSent(clock_.Now(), bytes_in_flight, sequence_number_, |
+ kMaxPacketSize, retransmittable_data)); |
+ pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, |
sequence_number_++, kMaxPacketSize, |
- HAS_RETRANSMITTABLE_DATA); |
+ retransmittable_data); |
} |
- void CheckAckIsSentImmediately() { |
- // In order for the ack to be sendable, the underlying sender must |
- // permit it to be sent immediately. |
- EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), |
- 0, |
- NO_RETRANSMITTABLE_DATA)) |
- .WillOnce(Return(zero_time_)); |
- // Verify that the ACK can be sent immediately. |
- EXPECT_EQ(zero_time_, |
- pacing_sender_->TimeUntilSend(clock_.Now(), |
- 0, |
- NO_RETRANSMITTABLE_DATA)); |
+ void CheckPacketIsSentImmediately() { |
+ CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight); |
+ } |
- // Actually send the packet. |
- EXPECT_CALL(*mock_sender_, |
- OnPacketSent(clock_.Now(), 0, sequence_number_, |
- kMaxPacketSize, NO_RETRANSMITTABLE_DATA)); |
- pacing_sender_->OnPacketSent(clock_.Now(), 0, |
- sequence_number_++, kMaxPacketSize, |
- NO_RETRANSMITTABLE_DATA); |
+ void CheckAckIsSentImmediately() { |
+ CheckPacketIsSentImmediately(NO_RETRANSMITTABLE_DATA, kBytesInFlight); |
} |
void CheckPacketIsDelayed(QuicTime::Delta delay) { |
@@ -99,6 +92,13 @@ class PacingSenderTest : public ::testing::Test { |
} |
} |
+ void UpdateRtt() { |
+ EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
+ SendAlgorithmInterface::CongestionVector empty_map; |
+ pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, |
+ empty_map); |
+ } |
+ |
const QuicTime::Delta zero_time_; |
const QuicTime::Delta infinite_time_; |
MockClock clock_; |
@@ -134,19 +134,15 @@ TEST_F(PacingSenderTest, SendNow) { |
} |
TEST_F(PacingSenderTest, VariousSending) { |
- // Configure pacing rate of 1 packet per 1 ms. |
- EXPECT_CALL(*mock_sender_, PacingRate()) |
- .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
- kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); |
+ // Configure pacing rate of 1 packet per 1 ms, no initial burst. |
+ InitPacingRate(0, QuicBandwidth::FromBytesAndTimeDelta( |
+ kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
// Now update the RTT and verify that packets are actually paced. |
- EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
- SendAlgorithmInterface::CongestionVector empty_map; |
- pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
+ UpdateRtt(); |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
- CheckPacketIsSentImmediately(); |
// The first packet was a "make up", then we sent two packets "into the |
// future", so the delay should be 2. |
@@ -187,7 +183,6 @@ TEST_F(PacingSenderTest, VariousSending) { |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
- CheckPacketIsSentImmediately(); |
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
// Wake up too early. |
@@ -199,16 +194,15 @@ TEST_F(PacingSenderTest, VariousSending) { |
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
} |
-TEST_F(PacingSenderTest, CongestionAvoidanceSending) { |
+// TODO(ianswett): Remove this test. |
+TEST_F(PacingSenderTest, DISABLED_CongestionAvoidanceSending) { |
// Configure pacing rate of 1 packet per 1 ms. |
EXPECT_CALL(*mock_sender_, PacingRate()) |
.WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
kMaxPacketSize * 1.25, QuicTime::Delta::FromMilliseconds(2)))); |
// Now update the RTT and verify that packets are actually paced. |
- EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
- SendAlgorithmInterface::CongestionVector empty_map; |
- pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
+ UpdateRtt(); |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
@@ -259,21 +253,12 @@ TEST_F(PacingSenderTest, CongestionAvoidanceSending) { |
} |
TEST_F(PacingSenderTest, InitialBurst) { |
- pacing_sender_.reset(); |
- mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
- pacing_sender_.reset(new PacingSender(mock_sender_, |
- QuicTime::Delta::FromMilliseconds(1), |
- 10)); |
- |
// Configure pacing rate of 1 packet per 1 ms. |
- EXPECT_CALL(*mock_sender_, PacingRate()) |
- .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
- kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); |
+ InitPacingRate(10, QuicBandwidth::FromBytesAndTimeDelta( |
+ kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
// Update the RTT and verify that the first 10 packets aren't paced. |
- EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
- SendAlgorithmInterface::CongestionVector empty_map; |
- pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
+ UpdateRtt(); |
// Send 10 packets, and verify that they are not paced. |
for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
@@ -284,24 +269,15 @@ TEST_F(PacingSenderTest, InitialBurst) { |
// future", so the delay should be 2ms. |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
- CheckPacketIsSentImmediately(); |
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
CheckPacketIsSentImmediately(); |
- // Next time TimeUntilSend is called with no bytes in flight, the tokens |
- // should be refilled and there should be no delay. |
- EXPECT_CALL(*mock_sender_, |
- TimeUntilSend(clock_.Now(), |
- 0, |
- HAS_RETRANSMITTABLE_DATA)). |
- WillOnce(Return(zero_time_)); |
- EXPECT_EQ(zero_time_, |
- pacing_sender_->TimeUntilSend(clock_.Now(), |
- 0, |
- HAS_RETRANSMITTABLE_DATA)); |
- for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
+ // Next time TimeUntilSend is called with no bytes in flight, pacing should |
+ // allow a packet to be sent, and when it's sent, the tokens are refilled. |
+ CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); |
+ for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
CheckPacketIsSentImmediately(); |
} |
@@ -309,21 +285,13 @@ TEST_F(PacingSenderTest, InitialBurst) { |
// future", so the delay should be 2ms. |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
- CheckPacketIsSentImmediately(); |
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
} |
TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
- pacing_sender_.reset(); |
- mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
- pacing_sender_.reset(new PacingSender(mock_sender_, |
- QuicTime::Delta::FromMilliseconds(1), |
- 10)); |
- |
// Configure pacing rate of 1 packet per 1 ms. |
- EXPECT_CALL(*mock_sender_, PacingRate()) |
- .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
- kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); |
+ InitPacingRate(10, QuicBandwidth::FromBytesAndTimeDelta( |
+ kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
// Send 10 packets, and verify that they are not paced. |
for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
@@ -334,7 +302,6 @@ TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
// future", so the delay should be 2ms. |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
- CheckPacketIsSentImmediately(); |
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
@@ -343,17 +310,9 @@ TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
// Next time TimeUntilSend is called with no bytes in flight, the tokens |
// should be refilled and there should be no delay. |
- EXPECT_CALL(*mock_sender_, |
- TimeUntilSend(clock_.Now(), |
- 0, |
- HAS_RETRANSMITTABLE_DATA)). |
- WillOnce(Return(zero_time_)); |
- EXPECT_EQ(zero_time_, |
- pacing_sender_->TimeUntilSend(clock_.Now(), |
- 0, |
- HAS_RETRANSMITTABLE_DATA)); |
+ CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); |
// Send 10 packets, and verify that they are not paced. |
- for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
+ for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
CheckPacketIsSentImmediately(); |
} |
@@ -361,9 +320,48 @@ TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
// future", so the delay should be 2ms. |
CheckPacketIsSentImmediately(); |
CheckPacketIsSentImmediately(); |
- CheckPacketIsSentImmediately(); |
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
} |
+TEST_F(PacingSenderTest, FastSending) { |
+ // Ensure the pacing sender paces, even when the inter-packet spacing is less |
+ // than the pacing granularity. |
+ InitPacingRate(10, |
+ QuicBandwidth::FromBytesAndTimeDelta( |
+ 2 * kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
+ |
+ // Update the RTT and verify that the first 10 packets aren't paced. |
+ UpdateRtt(); |
+ |
+ // Send 10 packets, and verify that they are not paced. |
+ for (int i = 0; i < kInitialBurstPackets; ++i) { |
+ CheckPacketIsSentImmediately(); |
+ } |
+ |
+ // The first packet was a "make up", then we sent two packets "into the |
+ // future", since it's 2 packets/ms, so the delay should be 1.5ms. |
+ CheckPacketIsSentImmediately(); |
+ CheckPacketIsSentImmediately(); |
+ CheckPacketIsSentImmediately(); |
+ CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); |
+ |
+ clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
+ CheckPacketIsSentImmediately(); |
+ |
+ // Next time TimeUntilSend is called with no bytes in flight, the tokens |
+ // should be refilled and there should be no delay. |
+ CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); |
+ for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
+ CheckPacketIsSentImmediately(); |
+ } |
+ |
+ // The first packet was a "make up", then we sent two packets "into the |
+ // future", so the delay should be 1.5ms. |
+ CheckPacketIsSentImmediately(); |
+ CheckPacketIsSentImmediately(); |
+ CheckPacketIsSentImmediately(); |
+ CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); |
+} |
+ |
} // namespace test |
} // namespace net |