diff --git a/tests/test_connection.py b/tests/test_connection.py index 19135be79167..bf2cb879d2a3 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -4815,31 +4815,54 @@ def test_networkevents(node_factory, executor): '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."): + 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'])