From d0c81301b5a7eae6e5c4257d6efd42d434504269 Mon Sep 17 00:00:00 2001 From: Akash Mondal Date: Tue, 2 Sep 2025 18:47:07 +0000 Subject: [PATCH] fix: quic transport mock in quic connection --- libp2p/transport/quic/connection.py | 10 +--------- tests/core/transport/quic/test_connection.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libp2p/transport/quic/connection.py b/libp2p/transport/quic/connection.py index 799008f1..1610bde9 100644 --- a/libp2p/transport/quic/connection.py +++ b/libp2p/transport/quic/connection.py @@ -58,12 +58,6 @@ class QUICConnection(IRawConnection, IMuxedConn): - COMPLETE connection ID management (fixes the original issue) """ - MAX_CONCURRENT_STREAMS = 256 - MAX_INCOMING_STREAMS = 1000 - MAX_OUTGOING_STREAMS = 1000 - CONNECTION_HANDSHAKE_TIMEOUT = 60.0 - CONNECTION_CLOSE_TIMEOUT = 10.0 - def __init__( self, quic_connection: QuicConnection, @@ -160,6 +154,7 @@ class QUICConnection(IRawConnection, IMuxedConn): self.CONNECTION_HANDSHAKE_TIMEOUT = ( transport._config.CONNECTION_HANDSHAKE_TIMEOUT ) + self.MAX_CONCURRENT_STREAMS = transport._config.MAX_CONCURRENT_STREAMS # Performance and monitoring self._connection_start_time = time.time() @@ -891,7 +886,6 @@ class QUICConnection(IRawConnection, IMuxedConn): This handles when the peer tells us to stop using a connection ID. """ logger.debug(f"🗑️ CONNECTION ID RETIRED: {event.connection_id.hex()}") - logger.debug(f"🗑️ CONNECTION ID RETIRED: {event.connection_id.hex()}") # Remove from available IDs and add to retired set self._available_connection_ids.discard(event.connection_id) @@ -909,11 +903,9 @@ class QUICConnection(IRawConnection, IMuxedConn): self._stats["connection_id_changes"] += 1 else: logger.warning("⚠️ No available connection IDs after retirement!") - logger.debug("⚠️ No available connection IDs after retirement!") else: self._current_connection_id = None logger.warning("⚠️ No available connection IDs after retirement!") - logger.debug("⚠️ No available connection IDs after retirement!") # Update statistics self._stats["connection_ids_retired"] += 1 diff --git a/tests/core/transport/quic/test_connection.py b/tests/core/transport/quic/test_connection.py index 06e304a9..40bfc96f 100644 --- a/tests/core/transport/quic/test_connection.py +++ b/tests/core/transport/quic/test_connection.py @@ -12,6 +12,7 @@ import trio from libp2p.crypto.ed25519 import create_new_key_pair from libp2p.peer.id import ID +from libp2p.transport.quic.config import QUICTransportConfig from libp2p.transport.quic.connection import QUICConnection from libp2p.transport.quic.exceptions import ( QUICConnectionClosedError, @@ -54,6 +55,12 @@ class TestQUICConnection: mock.reset_stream = Mock() return mock + @pytest.fixture + def mock_quic_transport(self): + mock = Mock() + mock._config = QUICTransportConfig() + return mock + @pytest.fixture def mock_resource_scope(self): """Create mock resource scope.""" @@ -61,7 +68,10 @@ class TestQUICConnection: @pytest.fixture def quic_connection( - self, mock_quic_connection: Mock, mock_resource_scope: MockResourceScope + self, + mock_quic_connection: Mock, + mock_quic_transport: Mock, + mock_resource_scope: MockResourceScope, ): """Create test QUIC connection with enhanced features.""" private_key = create_new_key_pair().private_key @@ -75,7 +85,7 @@ class TestQUICConnection: local_peer_id=peer_id, is_initiator=True, maddr=Multiaddr("/ip4/127.0.0.1/udp/4001/quic"), - transport=Mock(), + transport=mock_quic_transport, resource_scope=mock_resource_scope, security_manager=mock_security_manager, )