From 57002f3381a9aafbee4cce400cdb4b83430c0850 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 23 Sep 2022 14:32:30 +0930 Subject: [PATCH] pytest: fix flake in test_onchain_different_fees Sometimes, we haven't reconnected, and so the peer does not exist at all after the channel is forgotten: ``` 2022-09-22T22:49:59.3985374Z # Now, 100 blocks it should be done. 2022-09-22T22:49:59.3985656Z bitcoind.generate_block(100) 2022-09-22T22:49:59.3986112Z > wait_for(lambda: only_one(l1.rpc.listpeers()['peers'])['channels'] == []) 2022-09-22T22:49:59.3986338Z 2022-09-22T22:49:59.3986523Z tests/test_closing.py:2715: 2022-09-22T22:49:59.3986810Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 2022-09-22T22:49:59.3987241Z contrib/pyln-testing/pyln/testing/utils.py:90: in wait_for 2022-09-22T22:49:59.3987568Z while not success(): 2022-09-22T22:49:59.3987917Z tests/test_closing.py:2715: in 2022-09-22T22:49:59.3988389Z wait_for(lambda: only_one(l1.rpc.listpeers()['peers'])['channels'] == []) 2022-09-22T22:49:59.3988737Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 2022-09-22T22:49:59.3988908Z 2022-09-22T22:49:59.3988979Z arr = [] 2022-09-22T22:49:59.3989106Z 2022-09-22T22:49:59.3989209Z def only_one(arr): 2022-09-22T22:49:59.3989545Z """Many JSON RPC calls return an array; often we only expect a single entry 2022-09-22T22:49:59.3989849Z """ 2022-09-22T22:49:59.3990063Z > assert len(arr) == 1 2022-09-22T22:49:59.3990388Z E AssertionError ``` You can see it's empty from the call here: ``` 2022-09-22T22:49:59.6697941Z DEBUG:root:{ 2022-09-22T22:49:59.6698106Z "id": "-c:listpeers#42", 2022-09-22T22:49:59.6698179Z "result": { 2022-09-22T22:49:59.6698270Z "peers": [] 2022-09-22T22:49:59.6698346Z } 2022-09-22T22:49:59.6698422Z } ``` Signed-off-by: Rusty Russell --- tests/test_closing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_closing.py b/tests/test_closing.py index 4d18d561e..cd6e5242b 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -2712,8 +2712,10 @@ def test_onchain_different_fees(node_factory, bitcoind, executor): # Now, 100 blocks it should be done. bitcoind.generate_block(100) - wait_for(lambda: only_one(l1.rpc.listpeers()['peers'])['channels'] == []) - wait_for(lambda: only_one(l2.rpc.listpeers()['peers'])['channels'] == []) + + # May reconnect, may not: if not, peer does not exist! + wait_for(lambda: all(p['channels'] == [] for p in l1.rpc.listpeers()['peers'])) + wait_for(lambda: all(p['channels'] == [] for p in l2.rpc.listpeers()['peers'])) @pytest.mark.developer("needs DEVELOPER=1")