| Index: net/quic/quic_connection_test.cc
|
| diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc
|
| index 11d568b135411f9174972e40f3f441eca181eebc..95dcd12eda369019738af751ee03c1cdbabd104b 100644
|
| --- a/net/quic/quic_connection_test.cc
|
| +++ b/net/quic/quic_connection_test.cc
|
| @@ -260,7 +260,7 @@ class TestConnectionHelper : public QuicConnectionHelperInterface {
|
|
|
| class TestPacketWriter : public QuicPacketWriter {
|
| public:
|
| - explicit TestPacketWriter(QuicVersion version)
|
| + TestPacketWriter(QuicVersion version, MockClock *clock)
|
| : version_(version),
|
| framer_(SupportedVersions(version_)),
|
| last_packet_size_(0),
|
| @@ -270,7 +270,9 @@ class TestPacketWriter : public QuicPacketWriter {
|
| final_bytes_of_last_packet_(0),
|
| final_bytes_of_previous_packet_(0),
|
| use_tagging_decrypter_(false),
|
| - packets_write_attempts_(0) {
|
| + packets_write_attempts_(0),
|
| + clock_(clock),
|
| + write_pause_time_delta_(QuicTime::Delta::Zero()) {
|
| }
|
|
|
| // QuicPacketWriter interface
|
| @@ -299,6 +301,10 @@ class TestPacketWriter : public QuicPacketWriter {
|
| return WriteResult(WRITE_STATUS_BLOCKED, -1);
|
| }
|
| last_packet_size_ = packet.length();
|
| +
|
| + if (!write_pause_time_delta_.IsZero()) {
|
| + clock_->AdvanceTime(write_pause_time_delta_);
|
| + }
|
| return WriteResult(WRITE_STATUS_OK, last_packet_size_);
|
| }
|
|
|
| @@ -312,6 +318,11 @@ class TestPacketWriter : public QuicPacketWriter {
|
|
|
| void BlockOnNextWrite() { block_on_next_write_ = true; }
|
|
|
| + // Sets the amount of time that the writer should before the actual write.
|
| + void SetWritePauseTimeDelta(QuicTime::Delta delta) {
|
| + write_pause_time_delta_ = delta;
|
| + }
|
| +
|
| const QuicPacketHeader& header() { return framer_.header(); }
|
|
|
| size_t frame_count() const { return framer_.num_frames(); }
|
| @@ -392,6 +403,10 @@ class TestPacketWriter : public QuicPacketWriter {
|
| uint32 final_bytes_of_previous_packet_;
|
| bool use_tagging_decrypter_;
|
| uint32 packets_write_attempts_;
|
| + MockClock *clock_;
|
| + // If non-zero, the clock will pause during WritePacket for this amount of
|
| + // time.
|
| + QuicTime::Delta write_pause_time_delta_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestPacketWriter);
|
| };
|
| @@ -613,7 +628,7 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> {
|
| send_algorithm_(new StrictMock<MockSendAlgorithm>),
|
| loss_algorithm_(new MockLossAlgorithm()),
|
| helper_(new TestConnectionHelper(&clock_, &random_generator_)),
|
| - writer_(new TestPacketWriter(version())),
|
| + writer_(new TestPacketWriter(version(), &clock_)),
|
| factory_(writer_.get()),
|
| connection_(connection_id_, IPEndPoint(), helper_.get(),
|
| factory_, false, version()),
|
| @@ -976,6 +991,10 @@ class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> {
|
| EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1));
|
| }
|
|
|
| + void SetWritePauseTimeDelta(QuicTime::Delta delta) {
|
| + writer_->SetWritePauseTimeDelta(delta);
|
| + }
|
| +
|
| void CongestionBlockWrites() {
|
| EXPECT_CALL(*send_algorithm_,
|
| TimeUntilSend(_, _, _)).WillRepeatedly(
|
| @@ -1550,6 +1569,74 @@ TEST_P(QuicConnectionTest, BasicSending) {
|
| EXPECT_EQ(7u, least_unacked());
|
| }
|
|
|
| +// If FLAGS_quic_record_send_time_before_write is disabled, QuicConnection
|
| +// should record the packet sen-tdime after the packet is sent.
|
| +TEST_P(QuicConnectionTest, RecordSentTimeAfterPacketSent) {
|
| + ValueRestore<bool> old_flag(&FLAGS_quic_record_send_time_before_write, false);
|
| + // We're using a MockClock for the tests, so we have complete control over the
|
| + // time.
|
| + // Our recorded timestamp for the last packet sent time will be passed in to
|
| + // the send_algorithm. Make sure that it is set to the correct value.
|
| + QuicTime actual_recorded_send_time = QuicTime::Zero();
|
| + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
|
| + .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
|
| +
|
| + // First send without any pause and check the result.
|
| + QuicTime expected_recorded_send_time = clock_.Now();
|
| + connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
|
| + EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
|
| + << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
|
| + << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
|
| +
|
| + // Now pause during the write, and check the results.
|
| + actual_recorded_send_time = QuicTime::Zero();
|
| + const QuicTime::Delta kWritePauseTimeDelta =
|
| + QuicTime::Delta::FromMilliseconds(5000);
|
| + SetWritePauseTimeDelta(kWritePauseTimeDelta);
|
| + expected_recorded_send_time = clock_.Now().Add(kWritePauseTimeDelta);
|
| +
|
| + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
|
| + .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
|
| + connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr);
|
| + EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
|
| + << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
|
| + << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
|
| +}
|
| +
|
| +// If FLAGS_quic_record_send_time_before_write is enabled, QuicConnection should
|
| +// record the the packet sent-time prior to sending the packet.
|
| +TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) {
|
| + ValueRestore<bool> old_flag(&FLAGS_quic_record_send_time_before_write, true);
|
| + // We're using a MockClock for the tests, so we have complete control over the
|
| + // time.
|
| + // Our recorded timestamp for the last packet sent time will be passed in to
|
| + // the send_algorithm. Make sure that it is set to the correct value.
|
| + QuicTime actual_recorded_send_time = QuicTime::Zero();
|
| + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
|
| + .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
|
| +
|
| + // First send without any pause and check the result.
|
| + QuicTime expected_recorded_send_time = clock_.Now();
|
| + connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
|
| + EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
|
| + << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
|
| + << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
|
| +
|
| + // Now pause during the write, and check the results.
|
| + actual_recorded_send_time = QuicTime::Zero();
|
| + const QuicTime::Delta kWritePauseTimeDelta =
|
| + QuicTime::Delta::FromMilliseconds(5000);
|
| + SetWritePauseTimeDelta(kWritePauseTimeDelta);
|
| + expected_recorded_send_time = clock_.Now();
|
| +
|
| + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
|
| + .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
|
| + connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr);
|
| + EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
|
| + << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
|
| + << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
|
| +}
|
| +
|
| TEST_P(QuicConnectionTest, FECSending) {
|
| // All packets carry version info till version is negotiated.
|
| QuicPacketCreator* creator =
|
|
|