From ad9f4e15707e07d5ff544bce3d49c4bdfa1d5cee Mon Sep 17 00:00:00 2001 From: Arya Rathore Date: Mon, 18 May 2026 12:32:39 +0530 Subject: [PATCH 1/2] tests: make test_networkevents portable on macOS --- tests/test_connection.py | 49 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 19135be79167..ee5988287397 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -4814,32 +4814,55 @@ def test_networkevents(node_factory, executor): 'connect_attempted': True, 'reason': f'All addresses failed: 127.0.0.1:{l1.port}: Cryptographic handshake: peer closed connection (wrong key?). '}] - # Connect failed because no listener - with pytest.raises(RpcError, match="Connection establishment: Connection refused."): + # Connect failed because no listener + with pytest.raises( + RpcError, + match=r"Connection establishment: (Connection refused|Bad file descriptor)."): l1.rpc.connect(l2.info['id'], 'localhost', 1) + nevents = l1.rpc.listnetworkevents(start=5)['networkevents'] del only_one(nevents)['timestamp'] del only_one(nevents)['duration_nsec'] - assert nevents == [{'created_index': 5, - 'peer_id': l2.info['id'], - 'type': 'connect_fail', - 'connect_attempted': True, - 'reason': f'All addresses failed: 127.0.0.1:1: Connection establishment: Connection refused. '}] + assert len(nevents) == 1 + + event = only_one(nevents) + + assert event['created_index'] == 5 + assert event['peer_id'] == l2.info['id'] + assert event['type'] == 'connect_fail' + assert event['connect_attempted'] is True + + assert re.search( + r"All addresses failed: 127\.0\.0\.1:1: Connection establishment: " + r"(Connection refused|Bad file descriptor)\. ", + event['reason'] + ) # Connect failed because unreachable - with pytest.raises(RpcError, match="Connection establishment: Connection timed out."): + with pytest.raises( + RpcError, + match=r"Connection establishment: (Connection timed out|Bad file descriptor)."): l1.rpc.connect(l2.info['id'], '1.1.1.1', 8081) + nevents = l1.rpc.listnetworkevents(start=6)['networkevents'] del only_one(nevents)['timestamp'] del only_one(nevents)['duration_nsec'] - assert nevents == [{'created_index': 6, - 'peer_id': l2.info['id'], - 'type': 'connect_fail', - 'connect_attempted': True, - 'reason': f'All addresses failed: 1.1.1.1:8081: Connection establishment: Connection timed out. '}] + assert len(nevents) == 1 + + event = only_one(nevents) + + assert event['created_index'] == 6 + assert event['peer_id'] == l2.info['id'] + assert event['type'] == 'connect_fail' + assert event['connect_attempted'] is True + assert re.search( + r"All addresses failed: 1\.1\.1\.1:8081: Connection establishment: " + r"(Connection timed out|Bad file descriptor)\. ", + event['reason'] + ) # Connect failed because it doesn't advertize any addresses. with pytest.raises(RpcError, match="Unable to connect, no address known for peer"): l2.rpc.connect(l1.info['id']) From f0626c94459f57598a4256acd267015a72de9635 Mon Sep 17 00:00:00 2001 From: Arya Rathore Date: Tue, 19 May 2026 12:28:17 +0530 Subject: [PATCH 2/2] tests: make test_networkevents portable on macOS Handle macOS-specific connection failures in tests/test_connection.py::test_networkevents. On macOS Tahoe, failed connect attempts can surface as "Bad file descriptor" instead of the Linux-specific errors previously expected by the test. The assertions are updated to validate stable event fields directly while allowing platform-dependent connection error text. Changelog-None --- tests/test_connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index ee5988287397..bf2cb879d2a3 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -4814,7 +4814,7 @@ def test_networkevents(node_factory, executor): 'connect_attempted': True, 'reason': f'All addresses failed: 127.0.0.1:{l1.port}: Cryptographic handshake: peer closed connection (wrong key?). '}] - # Connect failed because no listener + # Connect failed because no listener with pytest.raises( RpcError, match=r"Connection establishment: (Connection refused|Bad file descriptor)."):