From bcd050a6109f1c402e6c87704f31293e072fbd1d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 26 Jun 2022 14:11:01 +0930 Subject: [PATCH] pytest: fix test_ping_timeout flake. We can hang up due to ping while waiting for channel to become active. But we don't even need an active channel for this test, so simplify. ``` ______________________________ test_ping_timeout _______________________________ [gw1] linux -- Python 3.7.13 /opt/hostedtoolcache/Python/3.7.13/x64/bin/python3 node_factory = @pytest.mark.developer("dev-disconnect required") def test_ping_timeout(node_factory): # Disconnects after this, but doesn't know it. l1_disconnects = ['xWIRE_PING'] l1, l2 = node_factory.line_graph(2, opts=[{'dev-no-reconnect': None, 'disconnect': l1_disconnects}, > {}]) tests/test_connection.py:3826: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ contrib/pyln-testing/pyln/testing/utils.py:1493: in line_graph self.join_nodes(nodes, fundchannel, fundamount, wait_for_announce, announce_channels) contrib/pyln-testing/pyln/testing/utils.py:1470: in join_nodes nodes[i].wait_channel_active(scids[i]) contrib/pyln-testing/pyln/testing/utils.py:1003: in wait_channel_active wait_for(lambda: self.is_channel_active(chanid)) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ success = . at 0x7f132c3ef830> timeout = 900 def wait_for(success, timeout=TIMEOUT): start_time = time.time() interval = 0.25 while not success(): time_left = start_time + timeout - time.time() if time_left <= 0: > raise ValueError("Timeout while waiting for {}", success) E ValueError: ('Timeout while waiting for {}', . at 0x7f132c3ef830>) ``` --- tests/test_connection.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index ae125f045..69df7bc4b 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -3841,12 +3841,15 @@ def test_ping_timeout(node_factory): # Disconnects after this, but doesn't know it. l1_disconnects = ['xWIRE_PING'] - l1, l2 = node_factory.line_graph(2, opts=[{'dev-no-reconnect': None, - 'disconnect': l1_disconnects}, - {}]) + l1, l2 = node_factory.get_nodes(2, opts=[{'dev-no-reconnect': None, + 'disconnect': l1_disconnects}, + {}]) + l1.rpc.connect(l2.info['id'], 'localhost', l2.port) + # Takes 15-45 seconds, then another to try second ping # Because of ping timer randomness we don't know which side hangs up first - wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'] is False, timeout=45 + 45 + 5) + wait_for(lambda: l1.rpc.listpeers(l2.info['id'])['peers'] == [], + timeout=45 + 45 + 5) wait_for(lambda: (l1.daemon.is_in_log('Last ping unreturned: hanging up') or l2.daemon.is_in_log('Last ping unreturned: hanging up')))