diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 0e2b30c1d..b67cb9c43 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -616,15 +616,11 @@ class LegacyLightningDTests(BaseLightningDTests): def test_multihop_payment(self): nodes = [self.node_factory.get_node() for _ in range(5)] - conn_futures = [nodes[i].connect(nodes[i+1], 0.01, async=True) for i in range(len(nodes)-1)] + for i in range(len(nodes)-1): + nodes[i].connect(nodes[i+1], 0.01) htlc_amount = 10000 - # Now wait for all of them - [f.result() for f in conn_futures] - - time.sleep(1) - # Manually add channel l2 -> l3 to l1 so that it can compute the route for i in range(len(nodes)-1): nodes[0].rpc.dev_add_route(nodes[i].info['id'], nodes[i+1].info['id'], 1, 1, 6, 6) diff --git a/tests/utils.py b/tests/utils.py index 5929e277d..bd607ad2d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -240,11 +240,13 @@ class LightningNode(object): self.bitcoin = btc self.executor = executor + # Use batch if you're doing more than one async. def connect(self, remote_node, capacity, async=False): # Collect necessary information addr = self.rpc.newaddr()['address'] txid = self.bitcoin.rpc.sendtoaddress(addr, capacity) tx = self.bitcoin.rpc.gettransaction(txid) + start_size = self.bitcoin.rpc.getmempoolinfo()['size'] def call_connect(): try: @@ -256,10 +258,13 @@ class LightningNode(object): t.start() def wait_connected(): - # TODO(cdecker) Monitor the mempool to see if its time to generate yet. - time.sleep(5) - - # The sleep should have given bitcoind time to add the tx to its mempool + # Up to 10 seconds to get tx into mempool. + start_time = time.time() + while self.bitcoin.rpc.getmempoolinfo()['size'] == start_size: + if time.time() > start_time + 10: + raise TimeoutError('No new transactions in mempool') + time.sleep(0.1) + self.bitcoin.rpc.generate(1) #fut.result(timeout=5)