Browse Source

pytest: make wait_for do exponential backoff, start at 0.25 seconds.

This doesn't alter runtime very much, but does reduce log spam.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
fee-tracking2
Rusty Russell 6 years ago
parent
commit
fcb5310873
  1. 6
      tests/test_connection.py
  2. 2
      tests/test_gossip.py
  3. 8
      tests/utils.py

6
tests/test_connection.py

@ -764,10 +764,10 @@ def test_channel_persistence(node_factory, bitcoind, executor):
wait_for(lambda: len(l2.rpc.listpeers()['peers']) == 1)
# Wait for the restored HTLC to finish
wait_for(lambda: only_one(l1.rpc.listpeers()['peers'][0]['channels'])['msatoshi_to_us'] == 99990000, interval=1)
wait_for(lambda: only_one(l1.rpc.listpeers()['peers'][0]['channels'])['msatoshi_to_us'] == 99990000)
wait_for(lambda: len([p for p in l1.rpc.listpeers()['peers'] if p['connected']]), interval=1)
wait_for(lambda: len([p for p in l2.rpc.listpeers()['peers'] if p['connected']]), interval=1)
wait_for(lambda: len([p for p in l1.rpc.listpeers()['peers'] if p['connected']]))
wait_for(lambda: len([p for p in l2.rpc.listpeers()['peers'] if p['connected']]))
# Now make sure this is really functional by sending a payment
l1.pay(l2, 10000)

2
tests/test_gossip.py

@ -543,7 +543,7 @@ def test_routing_gossip(node_factory, bitcoind):
return len(missing) == 0
for n in nodes:
wait_for(lambda: check_gossip(n), interval=1)
wait_for(lambda: check_gossip(n))
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")

8
tests/utils.py

@ -39,10 +39,14 @@ TIMEOUT = int(os.getenv("TIMEOUT", "60"))
VALGRIND = os.getenv("VALGRIND", config['VALGRIND']) == "1"
def wait_for(success, timeout=TIMEOUT, interval=0.1):
def wait_for(success, timeout=TIMEOUT):
start_time = time.time()
interval = 0.25
while not success() and time.time() < start_time + timeout:
time.sleep(interval)
interval *= 2
if interval > 5:
interval = 5
if time.time() > start_time + timeout:
raise ValueError("Error waiting for {}", success)
@ -570,7 +574,7 @@ class LightningNode(object):
wait_for(lambda: txid in self.bitcoin.rpc.getrawmempool())
def wait_channel_active(self, chanid):
wait_for(lambda: self.is_channel_active(chanid), interval=1)
wait_for(lambda: self.is_channel_active(chanid))
# This waits until gossipd sees channel_update in both directions
# (or for local channels, at least a local announcement)

Loading…
Cancel
Save