Remove MockClock from PacketSavingConnection, and use the MockClock in MockQuicConnectionHelper instead. PiperOrigin-RevId: 539970480
diff --git a/quiche/quic/test_tools/quic_test_utils.cc b/quiche/quic/test_tools/quic_test_utils.cc index e04f0ca..ecc08ac 100644 --- a/quiche/quic/test_tools/quic_test_utils.cc +++ b/quiche/quic/test_tools/quic_test_utils.cc
@@ -455,9 +455,9 @@ MockQuicConnectionHelper::~MockQuicConnectionHelper() {} -const QuicClock* MockQuicConnectionHelper::GetClock() const { return &clock_; } +const MockClock* MockQuicConnectionHelper::GetClock() const { return &clock_; } -QuicClock* MockQuicConnectionHelper::GetClock() { return &clock_; } +MockClock* MockQuicConnectionHelper::GetClock() { return &clock_; } QuicRandom* MockQuicConnectionHelper::GetRandomGenerator() { return &random_generator_; @@ -551,16 +551,18 @@ return false; } -PacketSavingConnection::PacketSavingConnection( - QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory, - Perspective perspective) - : MockQuicConnection(helper, alarm_factory, perspective) {} +PacketSavingConnection::PacketSavingConnection(MockQuicConnectionHelper* helper, + QuicAlarmFactory* alarm_factory, + Perspective perspective) + : MockQuicConnection(helper, alarm_factory, perspective), + mock_helper_(helper) {} PacketSavingConnection::PacketSavingConnection( - QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory, + MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, Perspective perspective, const ParsedQuicVersionVector& supported_versions) : MockQuicConnection(helper, alarm_factory, perspective, - supported_versions) {} + supported_versions), + mock_helper_(helper) {} PacketSavingConnection::~PacketSavingConnection() {} @@ -572,12 +574,13 @@ void PacketSavingConnection::SendOrQueuePacket(SerializedPacket packet) { encrypted_packets_.push_back(std::make_unique<QuicEncryptedPacket>( CopyBuffer(packet), packet.encrypted_length, true)); - clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); + MockClock& clock = *mock_helper_->GetClock(); + clock.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); // Transfer ownership of the packet to the SentPacketManager and the // ack notifier to the AckNotifierManager. OnPacketSent(packet.encryption_level, packet.transmission_type); QuicConnectionPeer::GetSentPacketManager(this)->OnPacketSent( - &packet, clock_.ApproximateNow(), NOT_RETRANSMISSION, + &packet, clock.ApproximateNow(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, true, ECN_NOT_ECT); } @@ -1132,7 +1135,7 @@ void CreateClientSessionForTest( QuicServerId server_id, QuicTime::Delta connection_start_time, const ParsedQuicVersionVector& supported_versions, - QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory, + MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, QuicCryptoClientConfig* crypto_client_config, PacketSavingConnection** client_connection, TestQuicSpdyClientSession** client_session) { @@ -1155,7 +1158,7 @@ void CreateServerSessionForTest( QuicServerId /*server_id*/, QuicTime::Delta connection_start_time, ParsedQuicVersionVector supported_versions, - QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory, + MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, QuicCryptoServerConfig* server_crypto_config, QuicCompressedCertsCache* compressed_certs_cache, PacketSavingConnection** server_connection,
diff --git a/quiche/quic/test_tools/quic_test_utils.h b/quiche/quic/test_tools/quic_test_utils.h index ab1ec88..4a054f3 100644 --- a/quiche/quic/test_tools/quic_test_utils.h +++ b/quiche/quic/test_tools/quic_test_utils.h
@@ -516,8 +516,8 @@ MockQuicConnectionHelper(const MockQuicConnectionHelper&) = delete; MockQuicConnectionHelper& operator=(const MockQuicConnectionHelper&) = delete; ~MockQuicConnectionHelper() override; - const QuicClock* GetClock() const override; - QuicClock* GetClock(); + const MockClock* GetClock() const override; + MockClock* GetClock(); QuicRandom* GetRandomGenerator() override; quiche::QuicheBufferAllocator* GetStreamSendBufferAllocator() override; void AdvanceTime(QuicTime::Delta delta); @@ -737,11 +737,11 @@ class PacketSavingConnection : public MockQuicConnection { public: - PacketSavingConnection(QuicConnectionHelperInterface* helper, + PacketSavingConnection(MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, Perspective perspective); - PacketSavingConnection(QuicConnectionHelperInterface* helper, + PacketSavingConnection(MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, Perspective perspective, const ParsedQuicVersionVector& supported_versions); @@ -761,7 +761,7 @@ // Number of packets in encrypted_packets that has been delivered to the peer // connection. size_t number_of_packets_delivered_ = 0; - MockClock clock_; + MockQuicConnectionHelper* mock_helper_ = nullptr; }; class MockQuicSession : public QuicSession { @@ -1540,7 +1540,7 @@ void CreateClientSessionForTest( QuicServerId server_id, QuicTime::Delta connection_start_time, const ParsedQuicVersionVector& supported_versions, - QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory, + MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, QuicCryptoClientConfig* crypto_client_config, PacketSavingConnection** client_connection, TestQuicSpdyClientSession** client_session); @@ -1563,7 +1563,7 @@ void CreateServerSessionForTest( QuicServerId server_id, QuicTime::Delta connection_start_time, ParsedQuicVersionVector supported_versions, - QuicConnectionHelperInterface* helper, QuicAlarmFactory* alarm_factory, + MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory, QuicCryptoServerConfig* server_crypto_config, QuicCompressedCertsCache* compressed_certs_cache, PacketSavingConnection** server_connection,