Browse Source

pytest: Consolidating sync_blockheight and fixing flaky test

ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
8e043fc448
  1. 21
      tests/test_lightningd.py

21
tests/test_lightningd.py

@ -53,19 +53,10 @@ def wait_for(success, timeout=30):
raise ValueError("Error waiting for {}", success) raise ValueError("Error waiting for {}", success)
def sync_blockheight(*args): def sync_blockheight(nodes):
while True: target = bitcoind.rpc.getblockcount()
target = bitcoind.rpc.getblockcount() for n in nodes:
all_up_to_date = True wait_for(lambda: n.rpc.getinfo()['blockheight'] == target)
for l in args:
if l.rpc.dev_blockheight()['blockheight'] != target:
all_up_to_date = False
if all_up_to_date:
return
# Sleep before spinning.
time.sleep(0.1)
def tearDownBitcoind(): def tearDownBitcoind():
global bitcoind global bitcoind
@ -478,7 +469,7 @@ class LightningDTests(BaseLightningDTests):
l1.bitcoin.rpc.generate(5) l1.bitcoin.rpc.generate(5)
# If they're at different block heights we can get spurious errors. # If they're at different block heights we can get spurious errors.
sync_blockheight(l1, l2, l3) sync_blockheight([l1, l2, l3])
chanid1 = l1.rpc.getpeer(l2.info['id'])['channel'] chanid1 = l1.rpc.getpeer(l2.info['id'])['channel']
chanid2 = l2.rpc.getpeer(l3.info['id'])['channel'] chanid2 = l2.rpc.getpeer(l3.info['id'])['channel']
@ -880,6 +871,8 @@ class LegacyLightningDTests(BaseLightningDTests):
nodes[0].rpc.dev_add_route(nodes[i].info['id'], nodes[i+1].info['id'], 1, 1, 6, 6) nodes[0].rpc.dev_add_route(nodes[i].info['id'], nodes[i+1].info['id'], 1, 1, 6, 6)
#l1.rpc.dev_add_route(l2.info['id'], l3.info['id'], 1, 1, 6, 6) #l1.rpc.dev_add_route(l2.info['id'], l3.info['id'], 1, 1, 6, 6)
sync_blockheight(nodes)
invoice = nodes[-1].rpc.invoice(htlc_amount, "multihop_payment") invoice = nodes[-1].rpc.invoice(htlc_amount, "multihop_payment")
route = nodes[0].rpc.getroute(nodes[-1].info['id'], htlc_amount, 1) route = nodes[0].rpc.getroute(nodes[-1].info['id'], htlc_amount, 1)
receipt = nodes[0].rpc.sendpay(route, invoice['rhash']) receipt = nodes[0].rpc.sendpay(route, invoice['rhash'])

Loading…
Cancel
Save