From eb869cf144f3b22a4d790f93f79ad1ad385121aa Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 19 May 2018 13:49:20 -0700 Subject: [PATCH] pytest: Make test_sendpay less flaky While 1 second is very generous, it resolving the HTLCs may take longer, so we just loop over this instead of making it one-shot Signed-off-by: Christian Decker --- tests/test_lightningd.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 45c6f807d..c2e8cecfc 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -1064,13 +1064,16 @@ class LightningDTests(BaseLightningDTests): assert l2.rpc.listinvoices('testpayment2')['invoices'][0]['msatoshi_received'] == rs['msatoshi'] # Balances should reflect it. - time.sleep(1) - p1 = l1.rpc.getpeer(l2.info['id'], 'info') - p2 = l2.rpc.getpeer(l1.info['id'], 'info') - assert p1['channels'][0]['msatoshi_to_us'] == 10**6 * 1000 - amt - assert p1['channels'][0]['msatoshi_total'] == 10**6 * 1000 - assert p2['channels'][0]['msatoshi_to_us'] == amt - assert p2['channels'][0]['msatoshi_total'] == 10**6 * 1000 + def check_balances(): + p1 = l1.rpc.getpeer(l2.info['id'], 'info') + p2 = l2.rpc.getpeer(l1.info['id'], 'info') + return ( + p1['channels'][0]['msatoshi_to_us'] == 10**6 * 1000 - amt and + p1['channels'][0]['msatoshi_total'] == 10**6 * 1000 and + p2['channels'][0]['msatoshi_to_us'] == amt and + p2['channels'][0]['msatoshi_total'] == 10**6 * 1000 + ) + wait_for(check_balances) # Repeat will "succeed", but won't actually send anything (duplicate) assert not l1.daemon.is_in_log('... succeeded')