From b2672dc35c785dab2aa1c27f370bcbad9bc21558 Mon Sep 17 00:00:00 2001 From: torlando-tech Date: Sun, 18 Jan 2026 14:54:59 -0500 Subject: [PATCH] test: add coverage for pending identity connection cleanup path Add test for _pending_identity_connections cleanup during successful identity handshake (lines 1272-1275), achieving 100% patch coverage for PR #38 changes. Co-Authored-By: Claude Opus 4.5 --- tests/test_v2_2_identity_handshake.py | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_v2_2_identity_handshake.py b/tests/test_v2_2_identity_handshake.py index 23b648d..e83a272 100644 --- a/tests/test_v2_2_identity_handshake.py +++ b/tests/test_v2_2_identity_handshake.py @@ -558,6 +558,40 @@ class TestDuplicateIdentityHandshakeRaceCondition: assert result is True, "16-byte data without known identity should be processed as handshake" assert interface.address_to_identity[central_address] == central_identity + def test_handshake_cleans_up_pending_identity_connection(self): + """Test that successful handshake cleans up _pending_identity_connections.""" + from unittest.mock import Mock + + driver = MockBLEDriver() + owner = MockOwner() + + config = {"name": "Test", "enable_peripheral": True} + interface = BLEInterface(owner, config) + interface.driver = driver + + # Mock get_peer_mtu which is needed during handshake processing + driver.get_peer_mtu = Mock(return_value=185) + + central_address = "11:22:33:44:55:66" + central_identity = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10' + + # Simulate that this address was waiting for identity handshake + interface._pending_identity_connections[central_address] = time.time() + + # Verify pending entry exists + assert central_address in interface._pending_identity_connections + + # Process handshake + result = interface._handle_identity_handshake(central_address, central_identity) + + # Verify handshake succeeded + assert result is True, "Handshake should succeed" + assert interface.address_to_identity[central_address] == central_identity + + # Verify pending identity connection was cleaned up + assert central_address not in interface._pending_identity_connections, \ + "Pending identity connection should be removed after successful handshake" + if __name__ == "__main__": pytest.main([__file__, "-v"])