diff options
Diffstat (limited to 'chromium/net/third_party/quiche/src/quic/core/quic_connection_test.cc')
-rw-r--r-- | chromium/net/third_party/quiche/src/quic/core/quic_connection_test.cc | 1170 |
1 files changed, 598 insertions, 572 deletions
diff --git a/chromium/net/third_party/quiche/src/quic/core/quic_connection_test.cc b/chromium/net/third_party/quiche/src/quic/core/quic_connection_test.cc index 3d923a2deac..3babced88b6 100644 --- a/chromium/net/third_party/quiche/src/quic/core/quic_connection_test.cc +++ b/chromium/net/third_party/quiche/src/quic/core/quic_connection_test.cc @@ -36,7 +36,6 @@ #include "net/third_party/quiche/src/quic/test_tools/quic_connection_peer.h" #include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h" #include "net/third_party/quiche/src/quic/test_tools/quic_packet_creator_peer.h" -#include "net/third_party/quiche/src/quic/test_tools/quic_packet_generator_peer.h" #include "net/third_party/quiche/src/quic/test_tools/quic_sent_packet_manager_peer.h" #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" #include "net/third_party/quiche/src/quic/test_tools/simple_data_producer.h" @@ -338,6 +337,7 @@ class TestPacketWriter : public QuicPacketWriter { final_bytes_of_previous_packet_(0), use_tagging_decrypter_(false), packets_write_attempts_(0), + connection_close_packets_(0), clock_(clock), write_pause_time_delta_(QuicTime::Delta::Zero()), max_packet_size_(kMaxOutgoingPacketSize), @@ -406,7 +406,9 @@ class TestPacketWriter : public QuicPacketWriter { last_packet_size_ = packet.length(); last_packet_header_ = framer_.header(); - + if (!framer_.connection_close_frames().empty()) { + ++connection_close_packets_; + } if (!write_pause_time_delta_.IsZero()) { clock_->AdvanceTime(write_pause_time_delta_); } @@ -514,6 +516,10 @@ class TestPacketWriter : public QuicPacketWriter { return framer_.path_response_frames(); } + const QuicEncryptedPacket* coalesced_packet() const { + return framer_.coalesced_packet(); + } + size_t last_packet_size() { return last_packet_size_; } const QuicPacketHeader& last_packet_header() const { @@ -550,6 +556,10 @@ class TestPacketWriter : public QuicPacketWriter { uint32_t packets_write_attempts() { return packets_write_attempts_; } + uint32_t connection_close_packets() const { + return connection_close_packets_; + } + void Reset() { framer_.Reset(); } void SetSupportedVersions(const ParsedQuicVersionVector& versions) { @@ -583,6 +593,7 @@ class TestPacketWriter : public QuicPacketWriter { uint32_t final_bytes_of_previous_packet_; bool use_tagging_decrypter_; uint32_t packets_write_attempts_; + uint32_t connection_close_packets_; MockClock* clock_; // If non-zero, the clock will pause during WritePacket for this amount of // time. @@ -631,6 +642,7 @@ class TestConnection : public QuicConnection { HasRetransmittableData retransmittable, bool has_ack, bool has_pending_frames) { + ScopedPacketFlusher flusher(this); char buffer[kMaxOutgoingPacketSize]; size_t encrypted_length = QuicConnectionPeer::GetFramer(this)->EncryptPayload( @@ -641,7 +653,7 @@ class TestConnection : public QuicConnection { encrypted_length, has_ack, has_pending_frames); if (retransmittable == HAS_RETRANSMITTABLE_DATA) { serialized_packet.retransmittable_frames.push_back( - QuicFrame(QuicStreamFrame())); + QuicFrame(QuicPingFrame())); } OnSerializedPacket(&serialized_packet); } @@ -668,7 +680,7 @@ class TestConnection : public QuicConnection { if (!QuicUtils::IsCryptoStreamId(transport_version(), id) && this->encryption_level() == ENCRYPTION_INITIAL) { this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); - if (perspective() == Perspective::IS_CLIENT && !IsHandshakeConfirmed()) { + if (perspective() == Perspective::IS_CLIENT && !IsHandshakeComplete()) { OnHandshakeComplete(); } if (version().SupportsAntiAmplificationLimit()) { @@ -769,14 +781,14 @@ class TestConnection : public QuicConnection { } // Enable path MTU discovery. Assumes that the test is performed from the - // client perspective and the higher value of MTU target is used. + // server perspective and the higher value of MTU target is used. void EnablePathMtuDiscovery(MockSendAlgorithm* send_algorithm) { - ASSERT_EQ(Perspective::IS_CLIENT, perspective()); + ASSERT_EQ(Perspective::IS_SERVER, perspective()); QuicConfig config; QuicTagVector connection_options; connection_options.push_back(kMTUH); - config.SetConnectionOptionsToSend(connection_options); + config.SetInitialReceivedConnectionOptions(connection_options); EXPECT_CALL(*send_algorithm, SetFromConfig(_, _)); SetFromConfig(config); @@ -964,7 +976,6 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { Perspective::IS_CLIENT, version()), creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), - generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), frame1_(0, false, 0, QuicStringPiece(data1)), frame2_(0, false, 3, QuicStringPiece(data2)), @@ -1016,10 +1027,8 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { frame1_.stream_id = stream_id; frame2_.stream_id = stream_id; connection_.set_visitor(&visitor_); - if (connection_.session_decides_what_to_write()) { - connection_.SetSessionNotifier(¬ifier_); - connection_.set_notifier(¬ifier_); - } + connection_.SetSessionNotifier(¬ifier_); + connection_.set_notifier(¬ifier_); connection_.SetSendAlgorithm(send_algorithm_); connection_.SetLossAlgorithm(loss_algorithm_.get()); EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); @@ -1034,23 +1043,22 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) .Times(AnyNumber()) .WillRepeatedly(Return(QuicBandwidth::Zero())); + EXPECT_CALL(*send_algorithm_, PopulateConnectionStats(_)) + .Times(AnyNumber()); EXPECT_CALL(*send_algorithm_, InSlowStart()).Times(AnyNumber()); EXPECT_CALL(*send_algorithm_, InRecovery()).Times(AnyNumber()); EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(AnyNumber()); EXPECT_CALL(visitor_, WillingAndAbleToWrite()).Times(AnyNumber()); + EXPECT_CALL(visitor_, OnPacketDecrypted(_)).Times(AnyNumber()); EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); - if (connection_.session_decides_what_to_write()) { - EXPECT_CALL(visitor_, OnCanWrite()) - .WillRepeatedly( - Invoke(¬ifier_, &SimpleSessionNotifier::OnCanWrite)); - } else { - EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); - } + EXPECT_CALL(visitor_, OnCanWrite()) + .WillRepeatedly(Invoke(¬ifier_, &SimpleSessionNotifier::OnCanWrite)); EXPECT_CALL(visitor_, ShouldKeepConnectionAlive()) .WillRepeatedly(Return(false)); EXPECT_CALL(visitor_, OnCongestionWindowChange(_)).Times(AnyNumber()); EXPECT_CALL(visitor_, OnPacketReceived(_, _, _)).Times(AnyNumber()); EXPECT_CALL(visitor_, OnForwardProgressConfirmed()).Times(AnyNumber()); + EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(AnyNumber()); EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) .WillRepeatedly(Return(QuicTime::Zero())); @@ -1120,7 +1128,10 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { QuicFrames frames; frames.push_back(QuicFrame(frame)); QuicPacketCreatorPeer::SetSendVersionInPacket( - &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); + &peer_creator_, + QuicPacketCreatorPeer::GetEncryptionLevel(&peer_creator_) < + ENCRYPTION_FORWARD_SECURE && + connection_.perspective() == Perspective::IS_SERVER); char buffer[kMaxOutgoingPacketSize]; SerializedPacket serialized_packet = @@ -1329,26 +1340,11 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { void SendRstStream(QuicStreamId id, QuicRstStreamErrorCode error, QuicStreamOffset bytes_written) { - if (connection_.session_decides_what_to_write()) { - notifier_.WriteOrBufferRstStream(id, error, bytes_written); - connection_.OnStreamReset(id, error); - return; - } - std::unique_ptr<QuicRstStreamFrame> rst_stream = - std::make_unique<QuicRstStreamFrame>(1, id, error, bytes_written); - if (connection_.SendControlFrame(QuicFrame(rst_stream.get()))) { - rst_stream.release(); - } + notifier_.WriteOrBufferRstStream(id, error, bytes_written); connection_.OnStreamReset(id, error); } - void SendPing() { - if (connection_.session_decides_what_to_write()) { - notifier_.WriteOrBufferPing(); - } else { - connection_.SendControlFrame(QuicFrame(QuicPingFrame(1))); - } - } + void SendPing() { notifier_.WriteOrBufferPing(); } void ProcessAckPacket(uint64_t packet_number, QuicAckFrame* frame) { if (packet_number > 1) { @@ -1536,8 +1532,8 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == nullptr); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_ACK_DATA, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_ACK_DATA)); } void BlockOnNextWrite() { @@ -1567,6 +1563,10 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { connection_.set_perspective(perspective); if (perspective == Perspective::IS_SERVER) { connection_.set_can_truncate_connection_ids(true); + QuicConnectionPeer::SetNegotiatedVersion(&connection_); + if (GetQuicReloadableFlag(quic_version_negotiated_by_default_at_server)) { + connection_.OnSuccessfulVersionNegotiation(); + } } QuicFramerPeer::SetPerspective(&peer_framer_, QuicUtils::InvertPerspective(perspective)); @@ -1574,16 +1574,9 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { void set_packets_between_probes_base( const QuicPacketCount packets_between_probes_base) { - if (GetQuicReloadableFlag(quic_mtu_discovery_v2)) { - QuicConnectionPeer::ReInitializeMtuDiscoverer( - &connection_, packets_between_probes_base, - QuicPacketNumber(packets_between_probes_base)); - } else { - QuicConnectionPeer::SetPacketsBetweenMtuProbes( - &connection_, packets_between_probes_base); - QuicConnectionPeer::SetNextMtuProbeAt( - &connection_, QuicPacketNumber(packets_between_probes_base)); - } + QuicConnectionPeer::ReInitializeMtuDiscoverer( + &connection_, packets_between_probes_base, + QuicPacketNumber(packets_between_probes_base)); } bool IsDefaultTestConfiguration() { @@ -1627,6 +1620,24 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { } } + void MtuDiscoveryTestInit() { + set_perspective(Perspective::IS_SERVER); + QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); + connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); + peer_creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); + // QuicFramer::GetMaxPlaintextSize uses the smallest max plaintext size + // across all encrypters. The initial encrypter used with IETF QUIC has a + // 16-byte overhead, while the NullEncrypter used throughout this test has a + // 12-byte overhead. This test tests behavior that relies on computing the + // packet size correctly, so by unsetting the initial encrypter, we avoid + // having a mismatch between the overheads for the encrypters used. In + // non-test scenarios all encrypters used for a given connection have the + // same overhead, either 12 bytes for ones using Google QUIC crypto, or 16 + // bytes for ones using TLS. + connection_.SetEncrypter(ENCRYPTION_INITIAL, nullptr); + EXPECT_TRUE(connection_.connected()); + } + QuicConnectionId connection_id_; QuicFramer framer_; @@ -1642,7 +1653,6 @@ class QuicConnectionTest : public QuicTestWithParam<TestParams> { std::unique_ptr<TestPacketWriter> writer_; TestConnection connection_; QuicPacketCreator* creator_; - QuicPacketGenerator* generator_; QuicSentPacketManager* manager_; StrictMock<MockQuicConnectionVisitor> visitor_; @@ -1727,8 +1737,6 @@ TEST_P(QuicConnectionTest, SelfAddressChangeAtClient) { } TEST_P(QuicConnectionTest, SelfAddressChangeAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); @@ -1758,8 +1766,6 @@ TEST_P(QuicConnectionTest, SelfAddressChangeAtServer) { } TEST_P(QuicConnectionTest, AllowSelfAddressChangeToMappedIpv4AddressAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); @@ -1793,7 +1799,6 @@ TEST_P(QuicConnectionTest, AllowSelfAddressChangeToMappedIpv4AddressAtServer) { } TEST_P(QuicConnectionTest, ClientAddressChangeAndPacketReordered) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); @@ -1832,7 +1837,6 @@ TEST_P(QuicConnectionTest, ClientAddressChangeAndPacketReordered) { } TEST_P(QuicConnectionTest, PeerAddressChangeAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); @@ -1870,7 +1874,6 @@ TEST_P(QuicConnectionTest, PeerAddressChangeAtServer) { } TEST_P(QuicConnectionTest, EffectivePeerAddressChangeAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); @@ -1956,7 +1959,6 @@ TEST_P(QuicConnectionTest, EffectivePeerAddressChangeAtServer) { } TEST_P(QuicConnectionTest, ReceivePaddedPingAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); @@ -2032,29 +2034,17 @@ TEST_P(QuicConnectionTest, WriteOutOfOrderQueuedPackets) { writer_->SetWritable(); connection_.SendConnectivityProbingPacket(writer_.get(), connection_.peer_address()); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); - connection_.OnCanWrite(); - return; - } - EXPECT_CALL(visitor_, - OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_QUIC_BUG(connection_.OnCanWrite(), - "Attempt to write packet:1 after:2"); - EXPECT_FALSE(connection_.connected()); - TestConnectionCloseQuicErrorCode(QUIC_INTERNAL_ERROR); - const std::vector<QuicConnectionCloseFrame>& connection_close_frames = - writer_->connection_close_frames(); - EXPECT_EQ("Packet written out of order.", - connection_close_frames[0].error_details); + EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); + connection_.OnCanWrite(); } TEST_P(QuicConnectionTest, DiscardQueuedPacketsAfterConnectionClose) { // Regression test for b/74073386. { InSequence seq; - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) + .Times(AtLeast(1)); + EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(AtLeast(1)); } set_perspective(Perspective::IS_CLIENT); @@ -2067,12 +2057,8 @@ TEST_P(QuicConnectionTest, DiscardQueuedPacketsAfterConnectionClose) { connection_.SendStreamDataWithString(/*id=*/2, "foo", 0, NO_FIN); EXPECT_FALSE(connection_.connected()); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - // No need to buffer packets. - EXPECT_EQ(0u, connection_.NumQueuedPackets()); - } else { - EXPECT_EQ(1u, connection_.NumQueuedPackets()); - } + // No need to buffer packets. + EXPECT_EQ(0u, connection_.NumQueuedPackets()); EXPECT_EQ(0u, connection_.GetStats().packets_discarded); connection_.OnCanWrite(); @@ -2080,7 +2066,6 @@ TEST_P(QuicConnectionTest, DiscardQueuedPacketsAfterConnectionClose) { } TEST_P(QuicConnectionTest, ReceiveConnectivityProbingAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); @@ -2139,7 +2124,6 @@ TEST_P(QuicConnectionTest, ReceiveConnectivityProbingAtServer) { } TEST_P(QuicConnectionTest, ReceiveReorderedConnectivityProbingAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); @@ -2196,7 +2180,6 @@ TEST_P(QuicConnectionTest, ReceiveReorderedConnectivityProbingAtServer) { } TEST_P(QuicConnectionTest, MigrateAfterProbingAtServer) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); EXPECT_EQ(Perspective::IS_SERVER, connection_.perspective()); @@ -2397,8 +2380,6 @@ TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { } TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - set_perspective(Perspective::IS_SERVER); connection_.SetMaxPacketLength(1000); @@ -2443,8 +2424,6 @@ TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { } TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSizeWhileWriterLimited) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - const QuicByteCount lower_max_packet_size = 1240; writer_->set_max_packet_size(lower_max_packet_size); set_perspective(Perspective::IS_SERVER); @@ -2708,18 +2687,13 @@ TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { connection_.SendStreamDataWithString(3, "foofoofoo", 9, NO_FIN); // Ack bundled. if (GetParam().no_stop_waiting) { - if (GetQuicReloadableFlag(quic_simplify_stop_waiting)) { - // Do not ACK acks. - EXPECT_EQ(1u, writer_->frame_count()); - } else { - EXPECT_EQ(2u, writer_->frame_count()); - } + // Do not ACK acks. + EXPECT_EQ(1u, writer_->frame_count()); } else { EXPECT_EQ(3u, writer_->frame_count()); } EXPECT_EQ(1u, writer_->stream_frames().size()); - if (GetParam().no_stop_waiting && - GetQuicReloadableFlag(quic_simplify_stop_waiting)) { + if (GetParam().no_stop_waiting) { EXPECT_TRUE(writer_->ack_frames().empty()); } else { EXPECT_FALSE(writer_->ack_frames().empty()); @@ -2852,9 +2826,11 @@ TEST_P(QuicConnectionTest, LeastUnackedLower) { // one. This should cause a connection error. QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 7); if (!GetParam().no_stop_waiting) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) + .Times(AtLeast(1)); EXPECT_CALL(visitor_, - OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); + OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)) + .Times(AtLeast(1)); } ProcessStopWaitingPacket(InitStopWaitingFrame(1)); if (!GetParam().no_stop_waiting) { @@ -2907,7 +2883,7 @@ TEST_P(QuicConnectionTest, AckUnsentData) { EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); QuicAckFrame frame = InitAckFrame(1); EXPECT_CALL(visitor_, OnCanWrite()).Times(0); ProcessAckPacket(&frame); @@ -3078,7 +3054,9 @@ TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); QuicConnection::ScopedPacketFlusher flusher(&connection_); connection_.SendStreamData3(); + connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); connection_.SendCryptoStreamData(); + connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); } EXPECT_EQ(0u, connection_.NumQueuedPackets()); EXPECT_FALSE(connection_.HasQueuedData()); @@ -3366,11 +3344,6 @@ TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); writer_->SetWritable(); connection_.OnCanWrite(); - if (!connection_.session_decides_what_to_write()) { - // OnCanWrite will cause RST_STREAM be sent again. - connection_.SendControlFrame(QuicFrame(new QuicRstStreamFrame( - 1, stream_id, QUIC_ERROR_PROCESSING_STREAM, 14))); - } size_t padding_frame_count = writer_->padding_frames().size(); EXPECT_EQ(padding_frame_count + 1u, writer_->frame_count()); EXPECT_EQ(1u, writer_->rst_stream_frames().size()); @@ -3381,11 +3354,7 @@ TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) { BlockOnNextWrite(); QuicStreamId stream_id = 2; - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.SendStreamDataWithString(stream_id, "foo", 0, NO_FIN); // Now that there is a queued packet, reset the stream. @@ -3393,20 +3362,9 @@ TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) { // Unblock the connection and verify that the RST_STREAM is sent and the data // packet is sent. - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) - .Times(AtLeast(1)); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) - .Times(AtLeast(2)); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); writer_->SetWritable(); connection_.OnCanWrite(); - if (!connection_.session_decides_what_to_write()) { - // OnCanWrite will cause RST_STREAM be sent again. - connection_.SendControlFrame(QuicFrame( - new QuicRstStreamFrame(1, stream_id, QUIC_STREAM_NO_ERROR, 14))); - } size_t padding_frame_count = writer_->padding_frames().size(); EXPECT_EQ(padding_frame_count + 1u, writer_->frame_count()); EXPECT_EQ(1u, writer_->rst_stream_frames().size()); @@ -3495,12 +3453,7 @@ TEST_P(QuicConnectionTest, CancelRetransmissionAlarmAfterResetStream) { // Ensure that the data is still in flight, but the retransmission alarm is no // longer set. EXPECT_GT(manager_->GetBytesInFlight(), 0u); - if (QuicConnectionPeer::GetSentPacketManager(&connection_) - ->fix_rto_retransmission()) { - EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); - } else { - EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); - } + EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); } TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) { @@ -3547,11 +3500,6 @@ TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); writer_->SetWritable(); connection_.OnCanWrite(); - if (!connection_.session_decides_what_to_write()) { - // OnCanWrite will cause this RST_STREAM_FRAME be sent again. - connection_.SendControlFrame(QuicFrame(new QuicRstStreamFrame( - 1, stream_id, QUIC_ERROR_PROCESSING_STREAM, 14))); - } size_t padding_frame_count = writer_->padding_frames().size(); EXPECT_EQ(padding_frame_count + 1u, writer_->frame_count()); ASSERT_EQ(1u, writer_->rst_stream_frames().size()); @@ -3613,12 +3561,8 @@ TEST_P(QuicConnectionTest, RetransmitAckedPacket) { EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _, _)) .WillOnce(SetArgPointee<5>(lost_packets)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, QuicPacketNumber(4), _, _)) - .Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, QuicPacketNumber(4), _, _)) + .Times(1); ProcessAckPacket(&nack_two); EXPECT_EQ(1u, connection_.NumQueuedPackets()); @@ -3628,15 +3572,8 @@ TEST_P(QuicConnectionTest, RetransmitAckedPacket) { QuicAckFrame ack_all = InitAckFrame(3); ProcessAckPacket(&ack_all); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, QuicPacketNumber(4), _, _)) - .Times(0); - } else { - // Unblock the socket and attempt to send the queued packets. We will always - // send the retransmission. - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, QuicPacketNumber(4), _, _)) - .Times(1); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, QuicPacketNumber(4), _, _)) + .Times(0); writer_->SetWritable(); connection_.OnCanWrite(); @@ -3674,8 +3611,7 @@ TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { } TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { - if (connection_.PtoEnabled() || - !connection_.session_decides_what_to_write()) { + if (connection_.PtoEnabled()) { return; } connection_.SetMaxTailLossProbes(0); @@ -3688,11 +3624,7 @@ TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { // Block the writer and ensure they're queued. BlockOnNextWrite(); clock_.AdvanceTime(DefaultRetransmissionTime()); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); connection_.GetRetransmissionAlarm()->Fire(); EXPECT_TRUE(connection_.HasQueuedData()); @@ -3700,12 +3632,7 @@ TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { writer_->SetWritable(); clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2 * DefaultRetransmissionTime().ToMicroseconds())); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); - } else { - // 2 RTOs + 1 TLP, which is buggy. - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); connection_.GetRetransmissionAlarm()->Fire(); connection_.OnCanWrite(); } @@ -3725,36 +3652,20 @@ TEST_P(QuicConnectionTest, WriteBlockedBufferedThenSent) { TEST_P(QuicConnectionTest, WriteBlockedThenSent) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); BlockOnNextWrite(); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); - } else { - EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); - } + EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); EXPECT_EQ(1u, connection_.NumQueuedPackets()); // The second packet should also be queued, in order to ensure packets are // never sent out of order. writer_->SetWritable(); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN); EXPECT_EQ(2u, connection_.NumQueuedPackets()); // Now both are sent in order when we unblock. - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); connection_.OnCanWrite(); EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); EXPECT_EQ(0u, connection_.NumQueuedPackets()); @@ -3779,12 +3690,7 @@ TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { writer_->SetWritable(); connection_.OnCanWrite(); - if (QuicConnectionPeer::GetSentPacketManager(&connection_) - ->fix_rto_retransmission()) { - EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); - } else { - EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); - } + EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 2)); } @@ -3867,8 +3773,8 @@ TEST_P(QuicConnectionTest, DoNotAddToWriteBlockedListAfterDisconnect) { writer_->SetWriteBlocked(); } EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, AddToWriteBlockedListIfBlockedOnFlushPackets) { @@ -3906,11 +3812,7 @@ TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) { EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _, _)) .WillOnce(SetArgPointee<5>(lost_packets)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); - if (connection_.session_decides_what_to_write()) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); ProcessAckPacket(&nack); } @@ -4036,8 +3938,7 @@ TEST_P(QuicConnectionTest, TLP) { } TEST_P(QuicConnectionTest, TailLossProbeDelayForStreamDataInTLPR) { - if (!connection_.session_decides_what_to_write() || - connection_.PtoEnabled()) { + if (connection_.PtoEnabled()) { return; } @@ -4072,8 +3973,7 @@ TEST_P(QuicConnectionTest, TailLossProbeDelayForStreamDataInTLPR) { } TEST_P(QuicConnectionTest, TailLossProbeDelayForNonStreamDataInTLPR) { - if (!connection_.session_decides_what_to_write() || - connection_.PtoEnabled()) { + if (connection_.PtoEnabled()) { return; } @@ -4089,7 +3989,7 @@ TEST_P(QuicConnectionTest, TailLossProbeDelayForNonStreamDataInTLPR) { // Sets retransmittable on wire. const QuicTime::Delta retransmittable_on_wire_timeout = QuicTime::Delta::FromMilliseconds(50); - connection_.set_retransmittable_on_wire_timeout( + connection_.set_initial_retransmittable_on_wire_timeout( retransmittable_on_wire_timeout); EXPECT_TRUE(connection_.connected()); @@ -4129,7 +4029,7 @@ TEST_P(QuicConnectionTest, TailLossProbeDelayForNonStreamDataInTLPR) { // The ping alarm is set for the ping timeout, not the shorter // retransmittable_on_wire_timeout. EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(QuicTime::Delta::FromSeconds(kPingTimeoutSecs), + EXPECT_EQ(connection_.ping_timeout(), connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Receive an ACK for the data packet. @@ -4184,7 +4084,7 @@ TEST_P(QuicConnectionTest, TailLossProbeDelayForNonStreamDataInTLPR) { // The ping alarm is set for the ping timeout, not the shorter // retransmittable_on_wire_timeout. EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(QuicTime::Delta::FromSeconds(kPingTimeoutSecs), + EXPECT_EQ(connection_.ping_timeout(), connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Advance a small period of time: 5ms. And receive a retransmitted ACK. @@ -4227,8 +4127,7 @@ TEST_P(QuicConnectionTest, RTO) { // Regression test of b/133771183. TEST_P(QuicConnectionTest, RtoWithNoDataToRetransmit) { - if (!connection_.session_decides_what_to_write() || - connection_.PtoEnabled()) { + if (connection_.PtoEnabled()) { return; } connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); @@ -4243,31 +4142,14 @@ TEST_P(QuicConnectionTest, RtoWithNoDataToRetransmit) { // Simulate the retransmission alarm firing. clock_.AdvanceTime(DefaultRetransmissionTime()); // RTO fires, but there is no packet to be RTOed. - if (GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.GetRetransmissionAlarm()->Fire(); - if (GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - EXPECT_EQ(1u, writer_->rst_stream_frames().size()); - } + EXPECT_EQ(1u, writer_->rst_stream_frames().size()); EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(40); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(20); - if (GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - EXPECT_CALL(visitor_, WillingAndAbleToWrite()) - .WillRepeatedly(Return(false)); - } else { - EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); - } - if (GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - EXPECT_CALL(visitor_, OnAckNeedsRetransmittableFrame()).Times(1); - } else { - // Since there is a buffered RST_STREAM, no retransmittable frame is bundled - // with ACKs. - EXPECT_CALL(visitor_, OnAckNeedsRetransmittableFrame()).Times(0); - } + EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(false)); + EXPECT_CALL(visitor_, OnAckNeedsRetransmittableFrame()).Times(1); // Receives packets 1 - 40. for (size_t i = 1; i <= 40; ++i) { ProcessDataPacket(i); @@ -4304,9 +4186,12 @@ TEST_P(QuicConnectionTest, RetransmitWithSameEncryptionLevel) { // Manually mark both packets for retransmission. connection_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); - - // Packet should have been sent with ENCRYPTION_INITIAL. - EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); + if (!connection_.version().CanSendCoalescedPackets()) { + // Packet should have been sent with ENCRYPTION_INITIAL. + // If connection can send coalesced packet, both retransmissions will be + // coalesced in the same UDP datagram. + EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); + } // Packet should have been sent with ENCRYPTION_ZERO_RTT. EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); @@ -4346,17 +4231,12 @@ TEST_P(QuicConnectionTest, use_tagging_decrypter(); connection_.SetEncrypter(ENCRYPTION_INITIAL, std::make_unique<TaggingEncrypter>(0x01)); - QuicPacketNumber packet_number; connection_.SendCryptoStreamData(); // Simulate the retransmission alarm firing and the socket blocking. BlockOnNextWrite(); clock_.AdvanceTime(DefaultRetransmissionTime()); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.GetRetransmissionAlarm()->Fire(); EXPECT_EQ(1u, connection_.NumQueuedPackets()); @@ -4506,26 +4386,13 @@ TEST_P(QuicConnectionTest, Buffer100NonDecryptablePacketsThenKeyChange) { TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { BlockOnNextWrite(); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); - } else { - // Make sure that RTO is not started when the packet is queued. - EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); - } + EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); // Test that RTO is started once we write to the socket. writer_->SetWritable(); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); connection_.OnCanWrite(); EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); } @@ -4542,8 +4409,8 @@ TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN); QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); EXPECT_TRUE(retransmission_alarm->IsSet()); - EXPECT_EQ(clock_.Now() + DefaultRetransmissionTime(), - retransmission_alarm->deadline()); + EXPECT_EQ(DefaultRetransmissionTime(), + retransmission_alarm->deadline() - clock_.Now()); // Advance the time right before the RTO, then receive an ack for the first // packet to delay the RTO. @@ -4554,8 +4421,8 @@ TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { // Now we have an RTT sample of DefaultRetransmissionTime(500ms), // so the RTO has increased to 2 * SRTT. EXPECT_TRUE(retransmission_alarm->IsSet()); - EXPECT_EQ(retransmission_alarm->deadline(), - clock_.Now() + 2 * DefaultRetransmissionTime()); + EXPECT_EQ(retransmission_alarm->deadline() - clock_.Now(), + 2 * DefaultRetransmissionTime()); // Move forward past the original RTO and ensure the RTO is still pending. clock_.AdvanceTime(2 * DefaultRetransmissionTime()); @@ -4780,8 +4647,8 @@ TEST_P(QuicConnectionTest, PingAfterSend) { GetNthClientInitiatedStreamId(0, connection_.transport_version()), "GET /", 0, FIN, nullptr); EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(QuicTime::Delta::FromSeconds(15), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Now recevie an ACK of the previous packet, which will move the // ping alarm forward. @@ -4793,9 +4660,9 @@ TEST_P(QuicConnectionTest, PingAfterSend) { EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); // The ping timer is set slightly less than 15 seconds in the future, because // of the 1s ping timer alarm granularity. - EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15) - - QuicTime::Delta::FromMilliseconds(5), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ( + QuicTime::Delta::FromSeconds(15) - QuicTime::Delta::FromMilliseconds(5), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); writer_->Reset(); clock_.AdvanceTime(QuicTime::Delta::FromSeconds(15)); @@ -4834,8 +4701,8 @@ TEST_P(QuicConnectionTest, ReducedPingTimeout) { GetNthClientInitiatedStreamId(0, connection_.transport_version()), "GET /", 0, FIN, nullptr); EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(10), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(QuicTime::Delta::FromSeconds(10), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Now recevie an ACK of the previous packet, which will move the // ping alarm forward. @@ -4847,9 +4714,9 @@ TEST_P(QuicConnectionTest, ReducedPingTimeout) { EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); // The ping timer is set slightly less than 10 seconds in the future, because // of the 1s ping timer alarm granularity. - EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(10) - - QuicTime::Delta::FromMilliseconds(5), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ( + QuicTime::Delta::FromSeconds(10) - QuicTime::Delta::FromMilliseconds(5), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); writer_->Reset(); clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); @@ -4873,10 +4740,7 @@ TEST_P(QuicConnectionTest, ReducedPingTimeout) { // Tests whether sending an MTU discovery packet to peer successfully causes the // maximum packet size to increase. TEST_P(QuicConnectionTest, SendMtuDiscoveryPacket) { - if (connection_.SupportsMultiplePacketNumberSpaces()) { - return; - } - EXPECT_TRUE(connection_.connected()); + MtuDiscoveryTestInit(); // Send an MTU probe. const size_t new_mtu = kDefaultMaxPacketSize + 100; @@ -4887,17 +4751,6 @@ TEST_P(QuicConnectionTest, SendMtuDiscoveryPacket) { EXPECT_EQ(new_mtu, mtu_probe_size); EXPECT_EQ(QuicPacketNumber(1u), creator_->packet_number()); - // QuicFramer::GetMaxPlaintextSize uses the smallest max plaintext size across - // all encrypters. The initial encrypter used with IETF QUIC has a 16-byte - // overhead, while the NullEncrypter used throughout this test has a 12-byte - // overhead. This test tests behavior that relies on computing the packet size - // correctly, so by unsetting the initial encrypter, we avoid having a - // mismatch between the overheads for the encrypters used. In non-test - // scenarios all encrypters used for a given connection have the same - // overhead, either 12 bytes for ones using Google QUIC crypto, or 16 bytes - // for ones using TLS. - connection_.SetEncrypter(ENCRYPTION_INITIAL, nullptr); - // Send more than MTU worth of data. No acknowledgement was received so far, // so the MTU should be at its old value. const std::string data(kDefaultMaxPacketSize + 1, '.'); @@ -4912,7 +4765,6 @@ TEST_P(QuicConnectionTest, SendMtuDiscoveryPacket) { // Acknowledge all packets so far. QuicAckFrame probe_ack = InitAckFrame(3); - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); ProcessAckPacket(&probe_ack); EXPECT_EQ(new_mtu, connection_.max_packet_length()); @@ -4926,7 +4778,7 @@ TEST_P(QuicConnectionTest, SendMtuDiscoveryPacket) { // Tests whether MTU discovery does not happen when it is not explicitly enabled // by the connection options. TEST_P(QuicConnectionTest, MtuDiscoveryDisabled) { - EXPECT_TRUE(connection_.connected()); + MtuDiscoveryTestInit(); const QuicPacketCount packets_between_probes_base = 10; set_packets_between_probes_base(packets_between_probes_base); @@ -4942,18 +4794,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryDisabled) { // Tests whether MTU discovery works when all probes are acknowledged on the // first try. TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { - EXPECT_TRUE(connection_.connected()); - - // QuicFramer::GetMaxPlaintextSize uses the smallest max plaintext size across - // all encrypters. The initial encrypter used with IETF QUIC has a 16-byte - // overhead, while the NullEncrypter used throughout this test has a 12-byte - // overhead. This test tests behavior that relies on computing the packet size - // correctly, so by unsetting the initial encrypter, we avoid having a - // mismatch between the overheads for the encrypters used. In non-test - // scenarios all encrypters used for a given connection have the same - // overhead, either 12 bytes for ones using Google QUIC crypto, or 16 bytes - // for ones using TLS. - connection_.SetEncrypter(ENCRYPTION_INITIAL, nullptr); + MtuDiscoveryTestInit(); const QuicPacketCount packets_between_probes_base = 5; set_packets_between_probes_base(packets_between_probes_base); @@ -4974,12 +4815,9 @@ TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) .WillOnce(SaveArg<3>(&probe_size)); connection_.GetMtuDiscoveryAlarm()->Fire(); - if (GetQuicReloadableFlag(quic_mtu_discovery_v2)) { - EXPECT_THAT(probe_size, InRange(connection_.max_packet_length(), - kMtuDiscoveryTargetPacketSizeHigh)); - } else { - EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, probe_size); - } + + EXPECT_THAT(probe_size, InRange(connection_.max_packet_length(), + kMtuDiscoveryTargetPacketSizeHigh)); const QuicPacketNumber probe_packet_number = FirstSendingPacketNumber() + packets_between_probes_base; @@ -4987,7 +4825,6 @@ TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { // Acknowledge all packets sent so far. QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) .Times(AnyNumber()); ProcessAckPacket(&probe_ack); @@ -4996,17 +4833,6 @@ TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { EXPECT_EQ(1u, connection_.mtu_probe_count()); - if (!GetQuicReloadableFlag(quic_mtu_discovery_v2)) { - // Send more packets, and ensure that none of them sets the alarm. - for (QuicPacketCount i = 0; i < 4 * packets_between_probes_base; i++) { - SendStreamDataToPeer(3, ".", packets_between_probes_base + i, NO_FIN, - nullptr); - ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); - } - - return; - } - QuicStreamOffset stream_offset = packets_between_probes_base; for (size_t num_probes = 1; num_probes < kMtuDiscoveryAttempts; ++num_probes) { @@ -5044,9 +4870,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { // Simulate the case where the first attempt to send a probe is write blocked, // and after unblock, the second attempt returns a MSG_TOO_BIG error. TEST_P(QuicConnectionTest, MtuDiscoveryWriteBlocked) { - EXPECT_TRUE(connection_.connected()); - - connection_.SetEncrypter(ENCRYPTION_INITIAL, nullptr); + MtuDiscoveryTestInit(); const QuicPacketCount packets_between_probes_base = 5; set_packets_between_probes_base(packets_between_probes_base); @@ -5065,9 +4889,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriteBlocked) { SendStreamDataToPeer(3, "!", packets_between_probes_base - 1, NO_FIN, nullptr); ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); BlockOnNextWrite(); EXPECT_EQ(0u, connection_.NumQueuedPackets()); connection_.GetMtuDiscoveryAlarm()->Fire(); @@ -5086,7 +4908,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriteBlocked) { // Tests whether MTU discovery works correctly when the probes never get // acknowledged. TEST_P(QuicConnectionTest, MtuDiscoveryFailed) { - EXPECT_TRUE(connection_.connected()); + MtuDiscoveryTestInit(); // Lower the number of probes between packets in order to make the test go // much faster. @@ -5106,8 +4928,6 @@ TEST_P(QuicConnectionTest, MtuDiscoveryFailed) { const QuicPacketCount number_of_packets = packets_between_probes_base * (1 << (kMtuDiscoveryAttempts + 1)); std::vector<QuicPacketNumber> mtu_discovery_packets; - // Called by the first ack. - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); // Called on many acks. EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) .Times(AnyNumber()); @@ -5168,21 +4988,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryFailed) { // Probe 3 times, the first one succeeds, then fails, then succeeds again. TEST_P(QuicConnectionTest, MtuDiscoverySecondProbeFailed) { - if (!GetQuicReloadableFlag(quic_mtu_discovery_v2)) { - return; - } - EXPECT_TRUE(connection_.connected()); - - // QuicFramer::GetMaxPlaintextSize uses the smallest max plaintext size across - // all encrypters. The initial encrypter used with IETF QUIC has a 16-byte - // overhead, while the NullEncrypter used throughout this test has a 12-byte - // overhead. This test tests behavior that relies on computing the packet size - // correctly, so by unsetting the initial encrypter, we avoid having a - // mismatch between the overheads for the encrypters used. In non-test - // scenarios all encrypters used for a given connection have the same - // overhead, either 12 bytes for ones using Google QUIC crypto, or 16 bytes - // for ones using TLS. - connection_.SetEncrypter(ENCRYPTION_INITIAL, nullptr); + MtuDiscoveryTestInit(); const QuicPacketCount packets_between_probes_base = 5; set_packets_between_probes_base(packets_between_probes_base); @@ -5213,7 +5019,6 @@ TEST_P(QuicConnectionTest, MtuDiscoverySecondProbeFailed) { // Acknowledge all packets sent so far. QuicAckFrame first_ack = InitAckFrame(probe_packet_number); - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) .Times(AnyNumber()); ProcessAckPacket(&first_ack); @@ -5271,18 +5076,7 @@ TEST_P(QuicConnectionTest, MtuDiscoverySecondProbeFailed) { // Tests whether MTU discovery works when the writer has a limit on how large a // packet can be. TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { - EXPECT_TRUE(connection_.connected()); - - // QuicFramer::GetMaxPlaintextSize uses the smallest max plaintext size across - // all encrypters. The initial encrypter used with IETF QUIC has a 16-byte - // overhead, while the NullEncrypter used throughout this test has a 12-byte - // overhead. This test tests behavior that relies on computing the packet size - // correctly, so by unsetting the initial encrypter, we avoid having a - // mismatch between the overheads for the encrypters used. In non-test - // scenarios all encrypters used for a given connection have the same - // overhead, either 12 bytes for ones using Google QUIC crypto, or 16 bytes - // for ones using TLS. - connection_.SetEncrypter(ENCRYPTION_INITIAL, nullptr); + MtuDiscoveryTestInit(); const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; writer_->set_max_packet_size(mtu_limit); @@ -5306,12 +5100,8 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) .WillOnce(SaveArg<3>(&probe_size)); connection_.GetMtuDiscoveryAlarm()->Fire(); - if (GetQuicReloadableFlag(quic_mtu_discovery_v2)) { - EXPECT_THAT(probe_size, - InRange(connection_.max_packet_length(), mtu_limit)); - } else { - EXPECT_EQ(mtu_limit, probe_size); - } + + EXPECT_THAT(probe_size, InRange(connection_.max_packet_length(), mtu_limit)); const QuicPacketNumber probe_sequence_number = FirstSendingPacketNumber() + packets_between_probes_base; @@ -5319,7 +5109,6 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { // Acknowledge all packets sent so far. QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number); - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) .Times(AnyNumber()); ProcessAckPacket(&probe_ack); @@ -5328,17 +5117,6 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { EXPECT_EQ(1u, connection_.mtu_probe_count()); - if (!GetQuicReloadableFlag(quic_mtu_discovery_v2)) { - // Send more packets, and ensure that none of them sets the alarm. - for (QuicPacketCount i = 0; i < 4 * packets_between_probes_base; i++) { - SendStreamDataToPeer(3, ".", packets_between_probes_base + i, NO_FIN, - nullptr); - ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); - } - - return; - } - QuicStreamOffset stream_offset = packets_between_probes_base; for (size_t num_probes = 1; num_probes < kMtuDiscoveryAttempts; ++num_probes) { @@ -5375,7 +5153,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { // Tests whether MTU discovery works when the writer returns an error despite // advertising higher packet length. TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) { - EXPECT_TRUE(connection_.connected()); + MtuDiscoveryTestInit(); const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; const QuicByteCount initial_mtu = connection_.max_packet_length(); @@ -5412,7 +5190,6 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) { // Acknowledge all packets sent so far, except for the lost probe. QuicAckFrame probe_ack = ConstructAckFrame(creator_->packet_number(), probe_number); - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); ProcessAckPacket(&probe_ack); EXPECT_EQ(initial_mtu, connection_.max_packet_length()); @@ -5428,7 +5205,7 @@ TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) { } TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) { - EXPECT_TRUE(connection_.connected()); + MtuDiscoveryTestInit(); const QuicPacketCount packets_between_probes_base = 10; set_packets_between_probes_base(packets_between_probes_base); @@ -5492,7 +5269,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterSend) { // This time, we should time out. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); clock_.AdvanceTime(five_ms); EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); connection_.GetTimeoutAlarm()->Fire(); @@ -5570,7 +5347,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterRetransmission) { // This time, we should time out. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); clock_.AdvanceTime(final_timeout - clock_.Now()); EXPECT_EQ(connection_.GetTimeoutAlarm()->deadline(), clock_.Now()); EXPECT_EQ(final_timeout, clock_.Now()); @@ -5601,7 +5378,7 @@ TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { client_config.ToHandshakeMessage(&msg, connection_.transport_version()); const QuicErrorCode error = config.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); connection_.SetFromConfig(config); EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); @@ -5650,8 +5427,8 @@ TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); EXPECT_FALSE(connection_.connected()); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_NETWORK_IDLE_TIMEOUT, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_NETWORK_IDLE_TIMEOUT)); } TEST_P(QuicConnectionTest, TimeoutAfterSendSilentCloseAndTLP) { @@ -5678,7 +5455,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterSendSilentCloseAndTLP) { client_config.ToHandshakeMessage(&msg, connection_.transport_version()); const QuicErrorCode error = config.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); connection_.SetFromConfig(config); EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); @@ -5705,7 +5482,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterSendSilentCloseAndTLP) { // This time, we should time out and send a connection close due to the TLP. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); clock_.AdvanceTime(connection_.GetTimeoutAlarm()->deadline() - clock_.ApproximateNow() + five_ms); connection_.GetTimeoutAlarm()->Fire(); @@ -5735,7 +5512,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterSendSilentCloseWithOpenStreams) { client_config.ToHandshakeMessage(&msg, connection_.transport_version()); const QuicErrorCode error = config.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); connection_.SetFromConfig(config); EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); @@ -5760,7 +5537,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterSendSilentCloseWithOpenStreams) { // This time, we should time out and send a connection close due to the TLP. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); clock_.AdvanceTime(connection_.GetTimeoutAlarm()->deadline() - clock_.ApproximateNow() + five_ms); connection_.GetTimeoutAlarm()->Fire(); @@ -5811,7 +5588,7 @@ TEST_P(QuicConnectionTest, TimeoutAfterReceive) { // This time, we should time out. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); clock_.AdvanceTime(five_ms); EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); connection_.GetTimeoutAlarm()->Fire(); @@ -5914,7 +5691,7 @@ TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) { // This time, we should time out. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); connection_.GetRetransmissionAlarm()->Fire(); EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); EXPECT_FALSE(connection_.connected()); @@ -6567,7 +6344,7 @@ TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) { } // Check that ack is sent and that delayed ack alarm is reset. if (GetParam().no_stop_waiting) { - EXPECT_EQ(1u, writer_->frame_count()); + EXPECT_EQ(writer_->padding_frames().size() + 1u, writer_->frame_count()); EXPECT_TRUE(writer_->stop_waiting_frames().empty()); } else { EXPECT_EQ(2u, writer_->frame_count()); @@ -6584,7 +6361,7 @@ TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) { ENCRYPTION_ZERO_RTT); // Check that ack is sent and that delayed ack alarm is reset. if (GetParam().no_stop_waiting) { - EXPECT_EQ(1u, writer_->frame_count()); + EXPECT_EQ(writer_->padding_frames().size() + 1u, writer_->frame_count()); EXPECT_TRUE(writer_->stop_waiting_frames().empty()); } else { EXPECT_EQ(2u, writer_->frame_count()); @@ -6720,7 +6497,7 @@ TEST_P(QuicConnectionTest, } // Check that ack is sent and that delayed ack alarm is reset. if (GetParam().no_stop_waiting) { - EXPECT_EQ(1u, writer_->frame_count()); + EXPECT_EQ(writer_->padding_frames().size() + 1u, writer_->frame_count()); EXPECT_TRUE(writer_->stop_waiting_frames().empty()); } else { EXPECT_EQ(2u, writer_->frame_count()); @@ -6737,7 +6514,7 @@ TEST_P(QuicConnectionTest, ENCRYPTION_ZERO_RTT); // Check that ack is sent and that delayed ack alarm is reset. if (GetParam().no_stop_waiting) { - EXPECT_EQ(1u, writer_->frame_count()); + EXPECT_EQ(writer_->padding_frames().size() + 1u, writer_->frame_count()); EXPECT_TRUE(writer_->stop_waiting_frames().empty()); } else { EXPECT_EQ(2u, writer_->frame_count()); @@ -6997,19 +6774,13 @@ TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { // Check that ack is bundled with outgoing data and the delayed ack // alarm is reset. if (GetParam().no_stop_waiting) { - if (GetQuicReloadableFlag(quic_simplify_stop_waiting)) { - // Do not ACK acks. - EXPECT_EQ(1u, writer_->frame_count()); - } else { - EXPECT_EQ(2u, writer_->frame_count()); - EXPECT_TRUE(writer_->stop_waiting_frames().empty()); - } + // Do not ACK acks. + EXPECT_EQ(1u, writer_->frame_count()); } else { EXPECT_EQ(3u, writer_->frame_count()); EXPECT_FALSE(writer_->stop_waiting_frames().empty()); } - if (GetParam().no_stop_waiting && - GetQuicReloadableFlag(quic_simplify_stop_waiting)) { + if (GetParam().no_stop_waiting) { EXPECT_TRUE(writer_->ack_frames().empty()); } else { EXPECT_FALSE(writer_->ack_frames().empty()); @@ -7028,8 +6799,8 @@ TEST_P(QuicConnectionTest, NoAckSentForClose) { EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); ProcessClosePacket(2); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, SendWhenDisconnected) { @@ -7047,8 +6818,8 @@ TEST_P(QuicConnectionTest, SendWhenDisconnected) { connection_.SendPacket(ENCRYPTION_INITIAL, 1, std::move(packet), HAS_RETRANSMITTABLE_DATA, false, false); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, SendConnectivityProbingWhenDisconnected) { @@ -7073,8 +6844,8 @@ TEST_P(QuicConnectionTest, SendConnectivityProbingWhenDisconnected) { "Not sending connectivity probing packet as connection is " "disconnected."); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, WriteBlockedAfterClientSendsConnectivityProbe) { @@ -7155,7 +6926,8 @@ TEST_P(QuicConnectionTest, PublicReset) { .WillOnce(Invoke(this, &QuicConnectionTest::SaveConnectionCloseFrame)); connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PUBLIC_RESET, saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PUBLIC_RESET)); } TEST_P(QuicConnectionTest, IetfStatelessReset) { @@ -7177,7 +6949,8 @@ TEST_P(QuicConnectionTest, IetfStatelessReset) { .WillOnce(Invoke(this, &QuicConnectionTest::SaveConnectionCloseFrame)); connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PUBLIC_RESET, saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PUBLIC_RESET)); } TEST_P(QuicConnectionTest, GoAway) { @@ -7201,7 +6974,7 @@ TEST_P(QuicConnectionTest, WindowUpdate) { QuicWindowUpdateFrame window_update; window_update.stream_id = 3; - window_update.byte_offset = 1234; + window_update.max_data = 1234; EXPECT_CALL(visitor_, OnWindowUpdateFrame(_)); ProcessFramePacket(QuicFrame(&window_update)); } @@ -7259,8 +7032,8 @@ TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_FALSE(connection_.connected()); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_VERSION, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_VERSION)); } TEST_P(QuicConnectionTest, BadVersionNegotiation) { @@ -7278,8 +7051,8 @@ TEST_P(QuicConnectionTest, BadVersionNegotiation) { ConstructReceivedPacket(*encrypted, QuicTime::Zero())); connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET)); } TEST_P(QuicConnectionTest, CheckSendStats) { @@ -7317,9 +7090,6 @@ TEST_P(QuicConnectionTest, CheckSendStats) { EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _, _)) .WillOnce(SetArgPointee<5>(lost_packets)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); - if (!connection_.session_decides_what_to_write()) { - EXPECT_CALL(visitor_, OnCanWrite()); - } EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessAckPacket(&nack_three); @@ -7387,8 +7157,8 @@ TEST_P(QuicConnectionTest, ProcessFramesIfPacketClosedConnection) { kSelfAddress, kPeerAddress, QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.extracted_error_code); + EXPECT_THAT(saved_connection_close_frame_.extracted_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, SelectMutualVersion) { @@ -7426,7 +7196,7 @@ TEST_P(QuicConnectionTest, ConnectionCloseWhenWritable) { EXPECT_EQ(1u, writer_->packets_write_attempts()); TriggerConnectionClose(); - EXPECT_EQ(2u, writer_->packets_write_attempts()); + EXPECT_LE(2u, writer_->packets_write_attempts()); } TEST_P(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { @@ -7450,10 +7220,10 @@ TEST_P(QuicConnectionTest, OnPacketSentDebugVisitor) { MockQuicConnectionDebugVisitor debug_visitor; connection_.set_debug_visitor(&debug_visitor); - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(1); + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)).Times(1); connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN); - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(1); + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)).Times(1); connection_.SendConnectivityProbingPacket(writer_.get(), connection_.peer_address()); } @@ -7494,7 +7264,7 @@ TEST_P(QuicConnectionTest, WindowUpdateInstigateAcks) { // Send a WINDOW_UPDATE frame. QuicWindowUpdateFrame window_update; window_update.stream_id = 3; - window_update.byte_offset = 1234; + window_update.max_data = 1234; EXPECT_CALL(visitor_, OnWindowUpdateFrame(_)); ProcessFramePacket(QuicFrame(&window_update)); @@ -7582,7 +7352,7 @@ TEST_P(QuicConnectionTest, SendPingImmediately) { CongestionBlockWrites(); connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(1); + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)).Times(1); EXPECT_CALL(debug_visitor, OnPingSent()).Times(1); connection_.SendControlFrame(QuicFrame(QuicPingFrame(1))); EXPECT_FALSE(connection_.HasQueuedData()); @@ -7594,7 +7364,7 @@ TEST_P(QuicConnectionTest, SendBlockedImmediately) { connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(1); + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)).Times(1); EXPECT_EQ(0u, connection_.GetStats().blocked_frames_sent); connection_.SendControlFrame(QuicFrame(new QuicBlockedFrame(1, 3))); EXPECT_EQ(1u, connection_.GetStats().blocked_frames_sent); @@ -7610,7 +7380,7 @@ TEST_P(QuicConnectionTest, FailedToSendBlockedFrames) { QuicBlockedFrame blocked(1, 3); EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(0); + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)).Times(0); EXPECT_EQ(0u, connection_.GetStats().blocked_frames_sent); connection_.SendControlFrame(QuicFrame(&blocked)); EXPECT_EQ(0u, connection_.GetStats().blocked_frames_sent); @@ -7631,8 +7401,8 @@ TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) { "Cannot send stream data with level: ENCRYPTION_INITIAL"); EXPECT_FALSE(connection_.connected()); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA)); } TEST_P(QuicConnectionTest, SetRetransmissionAlarmForCryptoPacket) { @@ -7668,8 +7438,8 @@ TEST_P(QuicConnectionTest, PathDegradingAlarmForCryptoPacket) { EXPECT_FALSE(connection_.IsPathDegrading()); QuicTime::Delta delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); // Fire the path degrading alarm, path degrading signal should be sent to // the visitor. @@ -7702,8 +7472,8 @@ TEST_P(QuicConnectionTest, PathDegradingAlarmForNonCryptoPackets) { QuicTime::Delta delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); // Send a second packet. The path degrading alarm's deadline should remain // the same. @@ -7731,8 +7501,8 @@ TEST_P(QuicConnectionTest, PathDegradingAlarmForNonCryptoPackets) { // Check the deadline of the path degrading alarm. delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); if (i == 0) { // Now receive an ACK of the second packet. Since there are no more @@ -7758,7 +7528,7 @@ TEST_P(QuicConnectionTest, PathDegradingAlarmForNonCryptoPackets) { TEST_P(QuicConnectionTest, RetransmittableOnWireSetsPingAlarm) { const QuicTime::Delta retransmittable_on_wire_timeout = QuicTime::Delta::FromMilliseconds(50); - connection_.set_retransmittable_on_wire_timeout( + connection_.set_initial_retransmittable_on_wire_timeout( retransmittable_on_wire_timeout); EXPECT_TRUE(connection_.connected()); @@ -7782,15 +7552,15 @@ TEST_P(QuicConnectionTest, RetransmittableOnWireSetsPingAlarm) { EXPECT_TRUE(connection_.GetPathDegradingAlarm()->IsSet()); QuicTime::Delta delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); ASSERT_TRUE(connection_.sent_packet_manager().HasInFlightPackets()); // The ping alarm is set for the ping timeout, not the shorter // retransmittable_on_wire_timeout. EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); QuicTime::Delta ping_delay = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); - EXPECT_EQ((clock_.ApproximateNow() + ping_delay), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(ping_delay, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Now receive an ACK of the packet. clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); @@ -7804,8 +7574,8 @@ TEST_P(QuicConnectionTest, RetransmittableOnWireSetsPingAlarm) { // retransmittable_on_wire_timeout. EXPECT_FALSE(connection_.GetPathDegradingAlarm()->IsSet()); EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(clock_.ApproximateNow() + retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Simulate firing the ping alarm and sending a PING. clock_.AdvanceTime(retransmittable_on_wire_timeout); @@ -7819,8 +7589,8 @@ TEST_P(QuicConnectionTest, RetransmittableOnWireSetsPingAlarm) { EXPECT_TRUE(connection_.GetPathDegradingAlarm()->IsSet()); delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); } // This test verifies that the connection marks path as degrading and does not @@ -7843,8 +7613,8 @@ TEST_P(QuicConnectionTest, NoPathDegradingAlarmIfPathIsDegrading) { // Check the deadline of the path degrading alarm. QuicTime::Delta delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); // Send a second packet. The path degrading alarm's deadline should remain // the same. @@ -7867,8 +7637,8 @@ TEST_P(QuicConnectionTest, NoPathDegradingAlarmIfPathIsDegrading) { // Check the deadline of the path degrading alarm. delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); // Advance time to the path degrading alarm's deadline and simulate // firing the path degrading alarm. This path will be considered as @@ -7909,8 +7679,8 @@ TEST_P(QuicConnectionTest, UnmarkPathDegradingOnForwardProgress) { // Check the deadline of the path degrading alarm. QuicTime::Delta delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); // Send a second packet. The path degrading alarm's deadline should remain // the same. @@ -7933,8 +7703,8 @@ TEST_P(QuicConnectionTest, UnmarkPathDegradingOnForwardProgress) { // Check the deadline of the path degrading alarm. delay = QuicConnectionPeer::GetSentPacketManager(&connection_) ->GetPathDegradingDelay(); - EXPECT_EQ(clock_.ApproximateNow() + delay, - connection_.GetPathDegradingAlarm()->deadline()); + EXPECT_EQ(delay, connection_.GetPathDegradingAlarm()->deadline() - + clock_.ApproximateNow()); // Advance time to the path degrading alarm's deadline and simulate // firing the alarm. @@ -7981,7 +7751,6 @@ TEST_P(QuicConnectionTest, NoPathDegradingOnServer) { // Ack data. clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); QuicAckFrame frame = InitAckFrame({{QuicPacketNumber(1u), QuicPacketNumber(2u)}}); @@ -8016,8 +7785,6 @@ TEST_P(QuicConnectionTest, MultipleCallsToCloseConnection) { } TEST_P(QuicConnectionTest, ServerReceivesChloOnNonCryptoStream) { - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - set_perspective(Perspective::IS_SERVER); QuicPacketCreatorPeer::SetSendVersionInPacket(creator_, false); @@ -8133,11 +7900,7 @@ TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedDueToWriteBlock) { EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); BlockOnNextWrite(); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.SendStreamData3(); // Now unblock the writer, become congestion control blocked, @@ -8145,11 +7908,7 @@ TEST_P(QuicConnectionTest, NotBecomeApplicationLimitedDueToWriteBlock) { writer_->SetWritable(); CongestionBlockWrites(); EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(false)); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1); connection_.OnCanWrite(); } @@ -8203,7 +7962,7 @@ TEST_P(QuicConnectionTest, SendDataWhenApplicationLimited) { ProcessAckPacket(&ack); } -TEST_P(QuicConnectionTest, DonotForceSendingAckOnPacketTooLarge) { +TEST_P(QuicConnectionTest, DoNotForceSendingAckOnPacketTooLarge) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); // Send an ack by simulating delayed ack alarm firing. ProcessPacket(1); @@ -8214,13 +7973,74 @@ TEST_P(QuicConnectionTest, DonotForceSendingAckOnPacketTooLarge) { EXPECT_CALL(visitor_, OnConnectionClosed(_, _)); SimulateNextPacketTooLarge(); connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN); - EXPECT_EQ(1u, writer_->frame_count()); - EXPECT_FALSE(writer_->connection_close_frames().empty()); + EXPECT_EQ(1u, writer_->connection_close_frames().size()); // Ack frame is not bundled in connection close packet. EXPECT_TRUE(writer_->ack_frames().empty()); + if (writer_->padding_frames().empty()) { + EXPECT_EQ(1u, writer_->frame_count()); + } else { + EXPECT_EQ(2u, writer_->frame_count()); + } + TestConnectionCloseQuicErrorCode(QUIC_PACKET_WRITE_ERROR); } +TEST_P(QuicConnectionTest, CloseConnectionAllLevels) { + SetQuicReloadableFlag(quic_close_all_encryptions_levels2, true); + + EXPECT_CALL(visitor_, OnConnectionClosed(_, _)); + const QuicErrorCode kQuicErrorCode = QUIC_INTERNAL_ERROR; + connection_.CloseConnection( + kQuicErrorCode, "Some random error message", + ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); + + EXPECT_EQ(2u, QuicConnectionPeer::GetNumEncryptionLevels(&connection_)); + + TestConnectionCloseQuicErrorCode(kQuicErrorCode); + EXPECT_EQ(1u, writer_->connection_close_frames().size()); + + if (!connection_.version().CanSendCoalescedPackets()) { + // Each connection close packet should be sent in distinct UDP packets. + EXPECT_EQ(QuicConnectionPeer::GetNumEncryptionLevels(&connection_), + writer_->connection_close_packets()); + EXPECT_EQ(QuicConnectionPeer::GetNumEncryptionLevels(&connection_), + writer_->packets_write_attempts()); + return; + } + + // A single UDP packet should be sent with multiple connection close packets + // coalesced together. + EXPECT_EQ(1u, writer_->packets_write_attempts()); + + // Only the first packet has been processed yet. + EXPECT_EQ(1u, writer_->connection_close_packets()); + + // ProcessPacket resets the visitor and frees the coalesced packet. + ASSERT_TRUE(writer_->coalesced_packet() != nullptr); + auto packet = writer_->coalesced_packet()->Clone(); + writer_->framer()->ProcessPacket(*packet); + EXPECT_EQ(1u, writer_->connection_close_packets()); + ASSERT_TRUE(writer_->coalesced_packet() == nullptr); +} + +TEST_P(QuicConnectionTest, CloseConnectionOneLevel) { + SetQuicReloadableFlag(quic_close_all_encryptions_levels2, false); + + EXPECT_CALL(visitor_, OnConnectionClosed(_, _)); + const QuicErrorCode kQuicErrorCode = QUIC_INTERNAL_ERROR; + connection_.CloseConnection( + kQuicErrorCode, "Some random error message", + ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); + + EXPECT_EQ(2u, QuicConnectionPeer::GetNumEncryptionLevels(&connection_)); + + TestConnectionCloseQuicErrorCode(kQuicErrorCode); + EXPECT_EQ(1u, writer_->connection_close_frames().size()); + EXPECT_EQ(1u, writer_->connection_close_packets()); + EXPECT_EQ(1u, writer_->packets_write_attempts()); + ASSERT_TRUE(writer_->coalesced_packet() == nullptr); +} + // Regression test for b/63620844. TEST_P(QuicConnectionTest, FailedToWriteHandshakePacket) { SimulateNextPacketTooLarge(); @@ -8279,13 +8099,19 @@ TEST_P(QuicConnectionTest, SendProbingRetransmissions) { } // Expect them retransmitted in cyclic order (foo, bar, test, foo, bar...). QuicPacketCount sent_count = 0; - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)) + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)) .WillRepeatedly(Invoke([this, &sent_count](const SerializedPacket&, - QuicPacketNumber, TransmissionType, QuicTime) { ASSERT_EQ(1u, writer_->stream_frames().size()); - // Identify the frames by stream offset (0, 3, 6, 0, 3...). - EXPECT_EQ(3 * (sent_count % 3), writer_->stream_frames()[0]->offset); + if (connection_.version().CanSendCoalescedPackets()) { + // There is a delay of sending coalesced packet, so (6, 0, 3, 6, + // 0...). + EXPECT_EQ(3 * ((sent_count + 2) % 3), + writer_->stream_frames()[0]->offset); + } else { + // Identify the frames by stream offset (0, 3, 6, 0, 3...). + EXPECT_EQ(3 * (sent_count % 3), writer_->stream_frames()[0]->offset); + } sent_count++; })); EXPECT_CALL(*send_algorithm_, ShouldSendProbingPacket()) @@ -8311,7 +8137,7 @@ TEST_P(QuicConnectionTest, MockQuicConnectionDebugVisitor debug_visitor; connection_.set_debug_visitor(&debug_visitor); - EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(0); + EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _)).Times(0); EXPECT_CALL(*send_algorithm_, ShouldSendProbingPacket()) .WillRepeatedly(Return(true)); EXPECT_CALL(visitor_, SendProbingData()).WillRepeatedly([this] { @@ -8325,7 +8151,7 @@ TEST_P(QuicConnectionTest, TEST_P(QuicConnectionTest, PingAfterLastRetransmittablePacketAcked) { const QuicTime::Delta retransmittable_on_wire_timeout = QuicTime::Delta::FromMilliseconds(50); - connection_.set_retransmittable_on_wire_timeout( + connection_.set_initial_retransmittable_on_wire_timeout( retransmittable_on_wire_timeout); EXPECT_TRUE(connection_.connected()); @@ -8346,8 +8172,8 @@ TEST_P(QuicConnectionTest, PingAfterLastRetransmittablePacketAcked) { // retransmittable_on_wire_timeout. EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); QuicTime::Delta ping_delay = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); - EXPECT_EQ((clock_.ApproximateNow() + ping_delay), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(ping_delay, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Advance 5ms, send a second retransmittable packet to the peer. clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); @@ -8370,9 +8196,8 @@ TEST_P(QuicConnectionTest, PingAfterLastRetransmittablePacketAcked) { EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); // The ping alarm has a 1 second granularity, and the clock has been advanced // 10ms since it was originally set. - EXPECT_EQ((clock_.ApproximateNow() + ping_delay - - QuicTime::Delta::FromMilliseconds(10)), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(ping_delay - QuicTime::Delta::FromMilliseconds(10), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Now receive an ACK of the second packet. This should set the // retransmittable-on-wire alarm now that no retransmittable packets are on @@ -8382,8 +8207,8 @@ TEST_P(QuicConnectionTest, PingAfterLastRetransmittablePacketAcked) { frame = InitAckFrame({{QuicPacketNumber(2), QuicPacketNumber(3)}}); ProcessAckPacket(&frame); EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(clock_.ApproximateNow() + retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Now receive a duplicate ACK of the second packet. This should not update // the ping alarm. @@ -8418,7 +8243,7 @@ TEST_P(QuicConnectionTest, PingAfterLastRetransmittablePacketAcked) { TEST_P(QuicConnectionTest, NoPingIfRetransmittablePacketSent) { const QuicTime::Delta retransmittable_on_wire_timeout = QuicTime::Delta::FromMilliseconds(50); - connection_.set_retransmittable_on_wire_timeout( + connection_.set_initial_retransmittable_on_wire_timeout( retransmittable_on_wire_timeout); EXPECT_TRUE(connection_.connected()); @@ -8439,8 +8264,8 @@ TEST_P(QuicConnectionTest, NoPingIfRetransmittablePacketSent) { // retransmittable_on_wire_timeout. EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); QuicTime::Delta ping_delay = QuicTime::Delta::FromSeconds(kPingTimeoutSecs); - EXPECT_EQ((clock_.ApproximateNow() + ping_delay), - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(ping_delay, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Now receive an ACK of the first packet. This should set the // retransmittable-on-wire alarm now that no retransmittable packets are on @@ -8452,8 +8277,8 @@ TEST_P(QuicConnectionTest, NoPingIfRetransmittablePacketSent) { InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(2)}}); ProcessAckPacket(&frame); EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(clock_.ApproximateNow() + retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Before the alarm fires, send another retransmittable packet. This should // cancel the retransmittable-on-wire alarm since now there's a @@ -8470,8 +8295,8 @@ TEST_P(QuicConnectionTest, NoPingIfRetransmittablePacketSent) { frame = InitAckFrame({{QuicPacketNumber(2), QuicPacketNumber(3)}}); ProcessAckPacket(&frame); EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); - EXPECT_EQ(clock_.ApproximateNow() + retransmittable_on_wire_timeout, - connection_.GetPingAlarm()->deadline()); + EXPECT_EQ(retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); // Simulate the alarm firing and check that a PING is sent. writer_->Reset(); @@ -8481,18 +8306,233 @@ TEST_P(QuicConnectionTest, NoPingIfRetransmittablePacketSent) { connection_.GetPingAlarm()->Fire(); size_t padding_frame_count = writer_->padding_frames().size(); if (GetParam().no_stop_waiting) { - if (GetQuicReloadableFlag(quic_simplify_stop_waiting)) { - // Do not ACK acks. - EXPECT_EQ(padding_frame_count + 1u, writer_->frame_count()); - } else { - EXPECT_EQ(padding_frame_count + 2u, writer_->frame_count()); - } + // Do not ACK acks. + EXPECT_EQ(padding_frame_count + 1u, writer_->frame_count()); } else { EXPECT_EQ(padding_frame_count + 3u, writer_->frame_count()); } ASSERT_EQ(1u, writer_->ping_frames().size()); } +// When there is no stream data received but are open streams, send the +// first few consecutive pings with aggressive retransmittable-on-wire +// timeout. Exponentially back off the retransmittable-on-wire ping timeout +// afterwards until it exceeds the default ping timeout. +TEST_P(QuicConnectionTest, BackOffRetransmittableOnWireTimeout) { + int max_aggressive_retransmittable_on_wire_ping_count = 5; + SetQuicFlag(FLAGS_quic_max_aggressive_retransmittable_on_wire_ping_count, + max_aggressive_retransmittable_on_wire_ping_count); + const QuicTime::Delta initial_retransmittable_on_wire_timeout = + QuicTime::Delta::FromMilliseconds(200); + connection_.set_initial_retransmittable_on_wire_timeout( + initial_retransmittable_on_wire_timeout); + + EXPECT_TRUE(connection_.connected()); + EXPECT_CALL(visitor_, ShouldKeepConnectionAlive()) + .WillRepeatedly(Return(true)); + + const char data[] = "data"; + // Advance 5ms, send a retransmittable data packet to the peer. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); + connection_.SendStreamDataWithString(1, data, 0, NO_FIN); + EXPECT_TRUE(connection_.sent_packet_manager().HasInFlightPackets()); + // The ping alarm is set for the ping timeout, not the shorter + // retransmittable_on_wire_timeout. + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(connection_.ping_timeout(), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(AnyNumber()); + EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) + .Times(AnyNumber()); + + // Verify that the first few consecutive retransmittable on wire pings are + // sent with aggressive timeout. + for (int i = 0; i <= max_aggressive_retransmittable_on_wire_ping_count; i++) { + // Receive an ACK of the previous packet. This should set the ping alarm + // with the initial retransmittable-on-wire timeout. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + // Simulate the alarm firing and check that a PING is sent. + writer_->Reset(); + EXPECT_CALL(visitor_, SendPing()).WillOnce(Invoke([this]() { + SendPing(); + })); + clock_.AdvanceTime(initial_retransmittable_on_wire_timeout); + connection_.GetPingAlarm()->Fire(); + } + + QuicTime::Delta retransmittable_on_wire_timeout = + initial_retransmittable_on_wire_timeout; + + // Verify subsequent pings are sent with timeout that is exponentially backed + // off. + while (retransmittable_on_wire_timeout * 2 < connection_.ping_timeout()) { + // Receive an ACK for the previous PING. This should set the + // ping alarm with backed off retransmittable-on-wire timeout. + retransmittable_on_wire_timeout = retransmittable_on_wire_timeout * 2; + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + // Simulate the alarm firing and check that a PING is sent. + writer_->Reset(); + EXPECT_CALL(visitor_, SendPing()).WillOnce(Invoke([this]() { + SendPing(); + })); + clock_.AdvanceTime(retransmittable_on_wire_timeout); + connection_.GetPingAlarm()->Fire(); + } + + // The ping alarm is set with default ping timeout. + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(connection_.ping_timeout(), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + // Receive an ACK for the previous PING. The ping alarm is set with an + // earlier deadline. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(connection_.ping_timeout() - QuicTime::Delta::FromMilliseconds(5), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); +} + +// This test verify that the count of consecutive aggressive pings is reset +// when new data is received. And it also verifies the connection resets +// the exponential back-off of the retransmittable-on-wire ping timeout +// after receiving new stream data. +TEST_P(QuicConnectionTest, ResetBackOffRetransmitableOnWireTimeout) { + int max_aggressive_retransmittable_on_wire_ping_count = 3; + SetQuicFlag(FLAGS_quic_max_aggressive_retransmittable_on_wire_ping_count, 3); + const QuicTime::Delta initial_retransmittable_on_wire_timeout = + QuicTime::Delta::FromMilliseconds(200); + connection_.set_initial_retransmittable_on_wire_timeout( + initial_retransmittable_on_wire_timeout); + + EXPECT_TRUE(connection_.connected()); + EXPECT_CALL(visitor_, ShouldKeepConnectionAlive()) + .WillRepeatedly(Return(true)); + EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(AnyNumber()); + EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) + .Times(AnyNumber()); + + const char data[] = "data"; + // Advance 5ms, send a retransmittable data packet to the peer. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); + connection_.SendStreamDataWithString(1, data, 0, NO_FIN); + EXPECT_TRUE(connection_.sent_packet_manager().HasInFlightPackets()); + // The ping alarm is set for the ping timeout, not the shorter + // retransmittable_on_wire_timeout. + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(connection_.ping_timeout(), + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + // Receive an ACK of the first packet. This should set the ping alarm with + // initial retransmittable-on-wire timeout since there is no retransmittable + // packet on the wire. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicAckFrame frame = + InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(2)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + // Simulate the alarm firing and check that a PING is sent. + writer_->Reset(); + EXPECT_CALL(visitor_, SendPing()).WillOnce(Invoke([this]() { SendPing(); })); + clock_.AdvanceTime(initial_retransmittable_on_wire_timeout); + connection_.GetPingAlarm()->Fire(); + + // Receive an ACK for the previous PING. Ping alarm will be set with + // aggressive timeout. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + QuicPacketNumber ack_num = creator_->packet_number(); + frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + // Process a data packet. + EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); + ProcessDataPacket(peer_creator_.packet_number() + 1); + QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, + peer_creator_.packet_number() + 1); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + // Verify the count of consecutive aggressive pings is reset. + for (int i = 0; i < max_aggressive_retransmittable_on_wire_ping_count; i++) { + // Receive an ACK of the previous packet. This should set the ping alarm + // with the initial retransmittable-on-wire timeout. + QuicPacketNumber ack_num = creator_->packet_number(); + QuicAckFrame frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + // Simulate the alarm firing and check that a PING is sent. + writer_->Reset(); + EXPECT_CALL(visitor_, SendPing()).WillOnce(Invoke([this]() { + SendPing(); + })); + clock_.AdvanceTime(initial_retransmittable_on_wire_timeout); + connection_.GetPingAlarm()->Fire(); + // Advance 5ms to receive next packet. + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + } + + // Receive another ACK for the previous PING. This should set the + // ping alarm with backed off retransmittable-on-wire timeout. + ack_num = creator_->packet_number(); + frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout * 2, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); + + writer_->Reset(); + EXPECT_CALL(visitor_, SendPing()).WillOnce(Invoke([this]() { SendPing(); })); + clock_.AdvanceTime(2 * initial_retransmittable_on_wire_timeout); + connection_.GetPingAlarm()->Fire(); + + // Process another data packet and a new ACK packet. The ping alarm is set + // with aggressive ping timeout again. + EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); + clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); + ProcessDataPacket(peer_creator_.packet_number() + 1); + QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, + peer_creator_.packet_number() + 1); + ack_num = creator_->packet_number(); + frame = InitAckFrame( + {{QuicPacketNumber(ack_num), QuicPacketNumber(ack_num + 1)}}); + ProcessAckPacket(&frame); + EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); + EXPECT_EQ(initial_retransmittable_on_wire_timeout, + connection_.GetPingAlarm()->deadline() - clock_.ApproximateNow()); +} + TEST_P(QuicConnectionTest, OnForwardProgressConfirmed) { EXPECT_CALL(visitor_, OnForwardProgressConfirmed()).Times(Exactly(0)); EXPECT_TRUE(connection_.connected()); @@ -8552,32 +8592,15 @@ TEST_P(QuicConnectionTest, ValidStatelessResetToken) { TEST_P(QuicConnectionTest, WriteBlockedWithInvalidAck) { EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); - } else { - EXPECT_CALL(visitor_, OnConnectionClosed(_, _)) - .WillOnce(Invoke(this, &QuicConnectionTest::SaveConnectionCloseFrame)); - } + EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); BlockOnNextWrite(); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); connection_.SendStreamDataWithString(5, "foo", 0, FIN); // This causes connection to be closed because packet 1 has not been sent yet. QuicAckFrame frame = InitAckFrame(1); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _, _)); - } + EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _, _)); ProcessAckPacket(1, &frame); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_EQ(0, connection_close_frame_count_); - } else { - EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_ACK_DATA, - saved_connection_close_frame_.quic_error_code); - } + EXPECT_EQ(0, connection_close_frame_count_); } TEST_P(QuicConnectionTest, SendMessage) { @@ -8594,33 +8617,36 @@ TEST_P(QuicConnectionTest, SendMessage) { // get sent, one contains stream frame, and the other only contains the // message frame. EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); - EXPECT_EQ( - MESSAGE_STATUS_SUCCESS, - connection_.SendMessage( - 1, MakeSpan(connection_.helper()->GetStreamSendBufferAllocator(), - QuicStringPiece( - message_data.data(), - connection_.GetCurrentLargestMessagePayload()), - &storage))); + EXPECT_EQ(MESSAGE_STATUS_SUCCESS, + connection_.SendMessage( + 1, + MakeSpan(connection_.helper()->GetStreamSendBufferAllocator(), + QuicStringPiece( + message_data.data(), + connection_.GetCurrentLargestMessagePayload()), + &storage), + false)); } // Fail to send a message if connection is congestion control blocked. EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); - EXPECT_EQ( - MESSAGE_STATUS_BLOCKED, - connection_.SendMessage( - 2, MakeSpan(connection_.helper()->GetStreamSendBufferAllocator(), - "message", &storage))); + EXPECT_EQ(MESSAGE_STATUS_BLOCKED, + connection_.SendMessage( + 2, + MakeSpan(connection_.helper()->GetStreamSendBufferAllocator(), + "message", &storage), + false)); // Always fail to send a message which cannot fit into one packet. EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - EXPECT_EQ( - MESSAGE_STATUS_TOO_LARGE, - connection_.SendMessage( - 3, MakeSpan(connection_.helper()->GetStreamSendBufferAllocator(), - QuicStringPiece( - message_data.data(), - connection_.GetCurrentLargestMessagePayload() + 1), - &storage))); + EXPECT_EQ(MESSAGE_STATUS_TOO_LARGE, + connection_.SendMessage( + 3, + MakeSpan(connection_.helper()->GetStreamSendBufferAllocator(), + QuicStringPiece( + message_data.data(), + connection_.GetCurrentLargestMessagePayload() + 1), + &storage), + false)); } // Test to check that the path challenge/path response logic works @@ -8743,7 +8769,6 @@ TEST_P(QuicConnectionTest, StopProcessingGQuicPacketInIetfQuicConnection) { 0u, QuicStringPiece())); EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); } - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); ProcessFramePacketWithAddresses(frame, kSelfAddress, kPeerAddress); // Let connection process a Google QUIC packet. @@ -8832,6 +8857,8 @@ TEST_P(QuicConnectionTest, PeerAcksPacketsInWrongPacketNumberSpace) { use_tagging_decrypter(); connection_.SetEncrypter(ENCRYPTION_INITIAL, std::make_unique<TaggingEncrypter>(0x01)); + connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, + std::make_unique<TaggingEncrypter>(0x01)); connection_.SendCryptoStreamData(); EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); @@ -8853,7 +8880,7 @@ TEST_P(QuicConnectionTest, PeerAcksPacketsInWrongPacketNumberSpace) { InitAckFrame({{QuicPacketNumber(2), QuicPacketNumber(4)}}); EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); ProcessFramePacketAtLevel(300, QuicFrame(&invalid_ack), ENCRYPTION_INITIAL); TestConnectionCloseQuicErrorCode(QUIC_INVALID_ACK_DATA); } @@ -9014,7 +9041,6 @@ TEST_P(QuicConnectionTest, UpdateClientConnectionIdFromFirstPacket) { if (!framer_.version().SupportsClientConnectionIds()) { return; } - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); set_perspective(Perspective::IS_SERVER); QuicPacketHeader header = ConstructPacketHeader(1, ENCRYPTION_INITIAL); header.source_connection_id = TestConnectionId(0x33); @@ -9185,10 +9211,6 @@ TEST_P(QuicConnectionTest, CoalescedPacketThatSavesFrames) { // Regresstion test for b/138962304. TEST_P(QuicConnectionTest, RtoAndWriteBlocked) { - if (!QuicConnectionPeer::GetSentPacketManager(&connection_) - ->fix_rto_retransmission()) { - return; - } EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); QuicStreamId stream_id = 2; @@ -9215,10 +9237,6 @@ TEST_P(QuicConnectionTest, RtoAndWriteBlocked) { // Regresstion test for b/138962304. TEST_P(QuicConnectionTest, TlpAndWriteBlocked) { - if (!QuicConnectionPeer::GetSentPacketManager(&connection_) - ->fix_rto_retransmission()) { - return; - } EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); connection_.SetMaxTailLossProbes(1); @@ -9236,11 +9254,7 @@ TEST_P(QuicConnectionTest, TlpAndWriteBlocked) { EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 3); - if (GetQuicReloadableFlag(quic_treat_queued_packets_as_sent)) { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); - } else { - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); - } + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); // Retransmission timer fires in TLP mode. connection_.GetRetransmissionAlarm()->Fire(); // Verify one packets is forced flushed when writer is blocked. @@ -9249,9 +9263,7 @@ TEST_P(QuicConnectionTest, TlpAndWriteBlocked) { // Regresstion test for b/139375344. TEST_P(QuicConnectionTest, RtoForcesSendingPing) { - if (!QuicConnectionPeer::GetSentPacketManager(&connection_) - ->fix_rto_retransmission() || - connection_.PtoEnabled()) { + if (connection_.PtoEnabled()) { return; } EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); @@ -9289,12 +9301,7 @@ TEST_P(QuicConnectionTest, RtoForcesSendingPing) { } TEST_P(QuicConnectionTest, ProbeTimeout) { - if (!connection_.session_decides_what_to_write() || - !GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - return; - } SetQuicReloadableFlag(quic_enable_pto, true); - SetQuicReloadableFlag(quic_fix_rto_retransmission3, true); QuicConfig config; QuicTagVector connection_options; connection_options.push_back(k2PTO); @@ -9322,10 +9329,6 @@ TEST_P(QuicConnectionTest, ProbeTimeout) { } TEST_P(QuicConnectionTest, CloseConnectionAfter6ClientPTOs) { - if (!connection_.session_decides_what_to_write() || - !GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - return; - } SetQuicReloadableFlag(quic_enable_pto, true); QuicConfig config; QuicTagVector connection_options; @@ -9342,7 +9345,7 @@ TEST_P(QuicConnectionTest, CloseConnectionAfter6ClientPTOs) { 0, FIN, nullptr); // 5PTO + 1 connection close. - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(6)); // Fire the retransmission alarm 5 times. for (int i = 0; i < 5; ++i) { @@ -9364,10 +9367,6 @@ TEST_P(QuicConnectionTest, CloseConnectionAfter6ClientPTOs) { } TEST_P(QuicConnectionTest, CloseConnectionAfter7ClientPTOs) { - if (!connection_.session_decides_what_to_write() || - !GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - return; - } SetQuicReloadableFlag(quic_enable_pto, true); QuicConfig config; QuicTagVector connection_options; @@ -9397,7 +9396,7 @@ TEST_P(QuicConnectionTest, CloseConnectionAfter7ClientPTOs) { // Closes connection on 7th PTO. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); connection_.GetRetransmissionAlarm()->Fire(); EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); EXPECT_FALSE(connection_.connected()); @@ -9405,10 +9404,6 @@ TEST_P(QuicConnectionTest, CloseConnectionAfter7ClientPTOs) { } TEST_P(QuicConnectionTest, CloseConnectionAfter8ClientPTOs) { - if (!connection_.session_decides_what_to_write() || - !GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - return; - } SetQuicReloadableFlag(quic_enable_pto, true); QuicConfig config; QuicTagVector connection_options; @@ -9438,7 +9433,7 @@ TEST_P(QuicConnectionTest, CloseConnectionAfter8ClientPTOs) { // Closes connection on 8th PTO. EXPECT_CALL(visitor_, OnConnectionClosed(_, ConnectionCloseSource::FROM_SELF)); - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); connection_.GetRetransmissionAlarm()->Fire(); EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); EXPECT_FALSE(connection_.connected()); @@ -9482,7 +9477,6 @@ TEST_P(QuicConnectionTest, AntiAmplificationLimit) { if (!connection_.version().SupportsAntiAmplificationLimit()) { return; } - EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); EXPECT_CALL(visitor_, OnCryptoFrame(_)).Times(AnyNumber()); set_perspective(Perspective::IS_SERVER); @@ -9558,9 +9552,7 @@ TEST_P(QuicConnectionTest, ConnectionCloseFrameType) { // Regression test for b/137401387 and b/138962304. TEST_P(QuicConnectionTest, RtoPacketAsTwo) { - if (!QuicConnectionPeer::GetSentPacketManager(&connection_) - ->fix_rto_retransmission() || - connection_.PtoEnabled()) { + if (connection_.PtoEnabled()) { return; } connection_.SetMaxTailLossProbes(1); @@ -9603,10 +9595,6 @@ TEST_P(QuicConnectionTest, RtoPacketAsTwo) { } TEST_P(QuicConnectionTest, PtoSkipsPacketNumber) { - if (!connection_.session_decides_what_to_write() || - !GetQuicReloadableFlag(quic_fix_rto_retransmission3)) { - return; - } SetQuicReloadableFlag(quic_enable_pto, true); SetQuicReloadableFlag(quic_skip_packet_number_for_pto, true); QuicConfig config; @@ -9633,6 +9621,44 @@ TEST_P(QuicConnectionTest, PtoSkipsPacketNumber) { EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); } +TEST_P(QuicConnectionTest, SendCoalescedPackets) { + if (!connection_.version().CanSendCoalescedPackets()) { + return; + } + { + QuicConnection::ScopedPacketFlusher flusher(&connection_); + use_tagging_decrypter(); + connection_.SetEncrypter(ENCRYPTION_INITIAL, + std::make_unique<TaggingEncrypter>(0x01)); + connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); + connection_.SendCryptoDataWithString("foo", 0); + // Verify this packet is on hold. + EXPECT_EQ(0u, writer_->packets_write_attempts()); + + connection_.SetEncrypter(ENCRYPTION_HANDSHAKE, + std::make_unique<TaggingEncrypter>(0x02)); + connection_.SetDefaultEncryptionLevel(ENCRYPTION_HANDSHAKE); + connection_.SendCryptoDataWithString("bar", 3); + EXPECT_EQ(0u, writer_->packets_write_attempts()); + + connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, + std::make_unique<TaggingEncrypter>(0x03)); + connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); + SendStreamDataToPeer(2, "baz", 3, NO_FIN, nullptr); + } + // Verify all 3 packets are coalesced in the same UDP datagram. + EXPECT_EQ(1u, writer_->packets_write_attempts()); + EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); + // Verify the packet is padded to full. + EXPECT_EQ(connection_.max_packet_length(), writer_->last_packet_size()); + + // Verify packet process. + EXPECT_EQ(1u, writer_->crypto_frames().size()); + EXPECT_EQ(0u, writer_->stream_frames().size()); + // Verify there is coalesced packet. + EXPECT_NE(nullptr, writer_->coalesced_packet()); +} + } // namespace } // namespace test } // namespace quic |