This source file includes following definitions.
- pacing_sender_
- CheckPacketIsSentImmediately
- CheckAckIsSentImmediately
- CheckPacketIsDelayed
- TEST_F
- TEST_F
- TEST_F
#include "net/quic/congestion_control/pacing_sender.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/test_tools/mock_clock.h"
#include "net/quic/test_tools/quic_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::Return;
using testing::StrictMock;
namespace net {
namespace test {
class PacingSenderTest : public ::testing::Test {
protected:
PacingSenderTest()
: zero_time_(QuicTime::Delta::Zero()),
infinite_time_(QuicTime::Delta::Infinite()),
sequence_number_(1),
mock_sender_(new StrictMock<MockSendAlgorithm>()),
pacing_sender_(new PacingSender(mock_sender_,
QuicTime::Delta::FromMilliseconds(1))) {
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9));
}
virtual ~PacingSenderTest() {}
void CheckPacketIsSentImmediately() {
EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA))
.WillOnce(Return(zero_time_));
EXPECT_EQ(zero_time_,
pacing_sender_->TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA));
EXPECT_CALL(*mock_sender_,
OnPacketSent(clock_.Now(), sequence_number_, kMaxPacketSize,
HAS_RETRANSMITTABLE_DATA));
pacing_sender_->OnPacketSent(clock_.Now(), sequence_number_++,
kMaxPacketSize,
HAS_RETRANSMITTABLE_DATA);
}
void CheckAckIsSentImmediately() {
EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(),
NO_RETRANSMITTABLE_DATA))
.WillOnce(Return(zero_time_));
EXPECT_EQ(zero_time_,
pacing_sender_->TimeUntilSend(clock_.Now(),
NO_RETRANSMITTABLE_DATA));
EXPECT_CALL(*mock_sender_,
OnPacketSent(clock_.Now(), sequence_number_, kMaxPacketSize,
NO_RETRANSMITTABLE_DATA));
pacing_sender_->OnPacketSent(clock_.Now(), sequence_number_++,
kMaxPacketSize,
NO_RETRANSMITTABLE_DATA);
}
void CheckPacketIsDelayed(QuicTime::Delta delay) {
EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA))
.WillOnce(Return(zero_time_));
EXPECT_EQ(delay.ToMicroseconds(),
pacing_sender_->TimeUntilSend(
clock_.Now(), HAS_RETRANSMITTABLE_DATA).ToMicroseconds());
}
const QuicTime::Delta zero_time_;
const QuicTime::Delta infinite_time_;
MockClock clock_;
QuicPacketSequenceNumber sequence_number_;
StrictMock<MockSendAlgorithm>* mock_sender_;
scoped_ptr<PacingSender> pacing_sender_;
};
TEST_F(PacingSenderTest, NoSend) {
EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA))
.WillOnce(Return(infinite_time_));
EXPECT_EQ(infinite_time_,
pacing_sender_->TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA));
}
TEST_F(PacingSenderTest, SendNow) {
EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA))
.WillOnce(Return(zero_time_));
EXPECT_EQ(zero_time_,
pacing_sender_->TimeUntilSend(clock_.Now(),
HAS_RETRANSMITTABLE_DATA));
}
TEST_F(PacingSenderTest, VariousSending) {
EXPECT_CALL(*mock_sender_, BandwidthEstimate())
.WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta(
kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2))));
for (int i = 0 ; i < 1000; ++i) {
CheckPacketIsSentImmediately();
}
QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(1);
EXPECT_CALL(*mock_sender_, UpdateRtt(rtt));
pacing_sender_->UpdateRtt(rtt);
CheckPacketIsSentImmediately();
CheckPacketIsSentImmediately();
CheckPacketIsSentImmediately();
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2));
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2));
CheckPacketIsSentImmediately();
CheckPacketIsSentImmediately();
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2));
CheckAckIsSentImmediately();
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(4));
CheckPacketIsSentImmediately();
CheckPacketIsSentImmediately();
CheckPacketIsSentImmediately();
CheckPacketIsSentImmediately();
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2));
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2));
clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
CheckPacketIsSentImmediately();
CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2));
}
}
}