diff --git a/tests/test_lnpeer.py b/tests/test_lnpeer.py index 3b9b6f293..1a5d23185 100644 --- a/tests/test_lnpeer.py +++ b/tests/test_lnpeer.py @@ -782,8 +782,11 @@ class TestPeerDirect(TestPeer): ] async def pay(): for pnum in range(2): - lnaddr, pay_req = self.prepare_invoice(w2) - result, log = await w1.pay_invoice(pay_req) + for _attempt in range(3): + lnaddr, pay_req = self.prepare_invoice(w2) + result, log = await w1.pay_invoice(pay_req) + if result: + break self.assertEqual(result, True) gath.cancel() gath = asyncio.gather(pay(), *loop_tasks) @@ -1656,8 +1659,16 @@ class TestPeerDirect(TestPeer): min_final_cltv_delta=400, payment_secret=lnaddr1.payment_secret, ) - await asyncio.sleep(bob_wallet.MPP_EXPIRY // 2) # give bob time to receive the htlc bob_payment_key = bob_wallet._get_payment_key(lnaddr1.paymenthash).hex() + # wait until bob has received both HTLCs (anchor channels need more commitment round-trips) + deadline = time.monotonic() + bob_wallet.MPP_EXPIRY * 2 + while True: + mpp_set = bob_wallet.received_mpp_htlcs.get(bob_payment_key) + if mpp_set is not None and len(mpp_set.htlcs) >= 2: + break + if time.monotonic() > deadline: + self.fail(f"timed out waiting for bob to receive both HTLCs: {bob_wallet.received_mpp_htlcs=}") + await asyncio.sleep(0.05) assert bob_wallet.received_mpp_htlcs[bob_payment_key].resolution == RecvMPPResolution.WAITING assert len(bob_wallet.received_mpp_htlcs[bob_payment_key].htlcs) == 2 # now wait until bob expires the mpp (set) @@ -2128,7 +2139,7 @@ class TestPeerDirect(TestPeer): while not len(bob_w.received_mpp_htlcs) == 10 : waited += 0.1 await asyncio.sleep(0.1) - if waited > 2: + if waited > 5: raise TimeoutError() nonlocal do_benchmark do_benchmark = True @@ -2613,7 +2624,7 @@ class TestPeerForwarding(TestPeer): graph.workers['carol'].name: LNPeerAddr(host="127.0.0.1", port=9735, pubkey=graph.workers['carol'].node_keypair.pubkey), } with self.assertRaises(PaymentDone): - await self._run_mpp(graph,{'alice_uses_trampoline': True, 'attempts': 1}) + await self._run_mpp(graph,{'alice_uses_trampoline': True, 'attempts': 3}) async def test_payment_multipart_trampoline_legacy(self): graph = self.prepare_chans_and_peers_in_graph(self.GRAPH_DEFINITIONS['square_graph']) @@ -2673,7 +2684,7 @@ class TestPeerForwarding(TestPeer): include_routing_hints=True, test_hold_invoice=False, test_failure=False, - attempts=2, + attempts=5, sender_name="alice", destination_name="dave", trampoline_forwarders=("bob", "carol"), @@ -2685,7 +2696,14 @@ class TestPeerForwarding(TestPeer): async def pay(lnaddr, pay_req): self.assertEqual(PR_UNPAID, dest_w.get_payment_status(lnaddr.paymenthash, direction=RECEIVED)) - result, log = await sender_w.pay_invoice(pay_req, attempts=attempts) + for _nopathfound_retry in range(3): + try: + result, log = await sender_w.pay_invoice(pay_req, attempts=attempts) + break + except NoPathFound: + if _nopathfound_retry == 2: + raise + await asyncio.sleep(0.05) async with OldTaskGroup() as g: for peer in peers: await g.spawn(peer.wait_one_htlc_switch_iteration())