From 98679aa6cffe2733bc1d840d541ff779368d7a87 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 19 Dec 2024 11:25:14 +1030 Subject: [PATCH] pytest: fix flake in test_restorefrompeer. Just because we've seen the block doesn't mean onchaind has finished starting up. ``` _____________________________ test_restorefrompeer _____________________________ [gw0] linux -- Python 3.10.15 /home/runner/.cache/pypoetry/virtualenvs/cln-meta-project-AqJ9wMix-py3.10/bin/python node_factory = bitcoind = @unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3") def test_restorefrompeer(node_factory, bitcoind): """ Test restorefrompeer """ l1, l2 = node_factory.get_nodes(2, [{'broken_log': 'ERROR: Unknown commitment #.*, recovering our funds!', 'experimental-peer-storage': None, 'may_reconnect': True, 'allow_bad_gossip': True}, {'experimental-peer-storage': None, 'may_reconnect': True}]) l1.rpc.connect(l2.info['id'], 'localhost', l2.port) c12, _ = l1.fundchannel(l2, 10**5) assert l1.daemon.is_in_log('Peer storage sent!') assert l2.daemon.is_in_log('Peer storage sent!') l1.stop() os.unlink(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "lightningd.sqlite3")) l1.start() assert l1.daemon.is_in_log('Server started with public key') # If this happens fast enough, connect fails with "disconnected # during connection" try: l1.rpc.connect(l2.info['id'], 'localhost', l2.port) except RpcError as err: assert "disconnected during connection" in err.error['message'] l1.daemon.wait_for_log('peer_in WIRE_YOUR_PEER_STORAGE') assert l1.rpc.restorefrompeer()['stubs'][0] == _['channel_id'] l1.daemon.wait_for_log('peer_out WIRE_ERROR') l2.daemon.wait_for_log('State changed from CHANNELD_NORMAL to AWAITING_UNILATERAL') bitcoind.generate_block(5, wait_for_mempool=1) sync_blockheight(bitcoind, [l1, l2]) l1.daemon.wait_for_log(r'All outputs resolved.*') wait_for(lambda: l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") # Check if funds are recovered. assert l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN" > assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN" E AssertionError: assert 'FUNDING_SPEND_SEEN' == 'ONCHAIN' E - ONCHAIN E + FUNDING_SPEND_SEEN tests/test_misc.py:3044: AssertionError ``` Signed-off-by: Rusty Russell --- tests/test_misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 0e16f337fa39..9e1abd75ae4d 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3040,8 +3040,8 @@ def test_restorefrompeer(node_factory, bitcoind): wait_for(lambda: l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") # Check if funds are recovered. - assert l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN" - assert l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN" + wait_for(lambda: l1.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") + wait_for(lambda: l2.rpc.listfunds()["channels"][0]["state"] == "ONCHAIN") def test_commitfee_option(node_factory):