tests: lnpeer: make mpp_cleanup_after_expiry more robust
What changed, and why it matters
This commit only changes a test file. It makes an existing automated test more reliable by waiting for both payment parts to finish before checking the result, instead of assuming both finished at once. There is no change to the actual Electrum wallet or Lightning code that users run.
No security action needed. Treat as a normal test reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/test_lnpeer.py in the mpp_cleanup_after_expiry test. It replaces a single asyncio.wait_for(alice_htlc_resolved.wait(), …) call with an async_timeout guarded loop that waits until counters show both HTLCs resolved (nhtlc_success + nhtlc_failed == 2). This fixes a race condition in the test harness where the event could fire once while only one of two HTLCs had actually resolved, causing flaky CI failures. No production code is touched.
Changed components
tests/test_lnpeer.pyInspect captured patch +3 / −1
diff --git a/tests/test_lnpeer.py b/tests/test_lnpeer.py
index e1a9c0b..ed73385 100644
--- a/tests/test_lnpeer.py
+++ b/tests/test_lnpeer.py
@@ -1532,7 +1532,9 @@ class TestPeerDirect(TestPeer):
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)
- await asyncio.wait_for(alice_htlc_resolved.wait(), bob_wallet.MPP_EXPIRY * 3) # this can take some time, esp. on CI
+ async with util.async_timeout(bob_wallet.MPP_EXPIRY * 3): # this can take some time, esp. on CI
+ while nhtlc_success + nhtlc_failed < 2:
+ await alice_htlc_resolved.wait()
# check that bob failed the htlc
assert nhtlc_success == 0 and nhtlc_failed == 2
# check that bob deleted the mpp set as it should be expired and resolved now
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.