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>
This commit is contained in:
Rusty Russell
2018-10-10 09:41:55 +10:30
parent 84b9e3e72b
commit fcb5310873
3 changed files with 10 additions and 6 deletions

View File

@@ -764,10 +764,10 @@ def test_channel_persistence(node_factory, bitcoind, executor):
wait_for(lambda: len(l2.rpc.listpeers()['peers']) == 1) wait_for(lambda: len(l2.rpc.listpeers()['peers']) == 1)
# Wait for the restored HTLC to finish # 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 l1.rpc.listpeers()['peers'] if p['connected']]))
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 l2.rpc.listpeers()['peers'] if p['connected']]))
# Now make sure this is really functional by sending a payment # Now make sure this is really functional by sending a payment
l1.pay(l2, 10000) l1.pay(l2, 10000)

View File

@@ -543,7 +543,7 @@ def test_routing_gossip(node_factory, bitcoind):
return len(missing) == 0 return len(missing) == 0
for n in nodes: 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") @unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")

View File

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