From 3204c719121686d7bfe12ee0c6fe2b286faf8030 Mon Sep 17 00:00:00 2001 From: Dusty Daemon Date: Tue, 16 Jun 2026 19:15:16 -0400 Subject: [PATCH] flake: Fix test_graceful_htlc to be flexible for notifs The test_graceful_htlc test can receive an extra notification if the test is running slowly enough. This changes how the test looks at notifications by explicitly incrementing the notification index. Then, we make it notice and ignore the first RCVD_ADD_REVOCATION notification, which is unwanted in the test but can occur if the server is running slow enough. Changelog-None --- tests/test_misc.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 98432502de70..91af3d7d7076 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -4412,9 +4412,20 @@ def capture(message, **kwargs): fut = executor.submit(run_graceful) + inotif = 0 + # Wait until graceful has sent at least one HTLC expiry notification - wait_for(lambda: len(notifications) == 1) - wait_for(lambda: notifications[0] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)') + wait_for(lambda: len(notifications) >= inotif + 1) + + # Depending on on timing between the sendpay and `l2.rpc.graceful`, we may get + # RCVD_ADD_REVOCATION or we may be too late to get that. + if notifications[inotif] == f'Next HTLC RCVD_ADD_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)': + # If we get RCVD_ADD_REVOCATION, ignore it and move onto the next notification + inotif += 1 + wait_for(lambda: len(notifications) >= inotif + 1) + + wait_for(lambda: notifications[inotif] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)') + inotif += 1 # This will tell us about htlcs and the peers (peers unordered) ret = l2.rpc.graceful(1) @@ -4425,12 +4436,16 @@ def capture(message, **kwargs): # Close incoming connection, so incoming HTLC gets stuck. l1.rpc.disconnect(l2.info['id'], force=True) - wait_for(lambda: notifications[-1] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)') + wait_for(lambda: len(notifications) >= inotif + 1) + wait_for(lambda: notifications[inotif] == f'Next HTLC SENT_ADD_ACK_REVOCATION expires at block #118 (10 blocks from now) going to peer {l3.info["id"]} (connected)') + inotif += 1 # Release the hold so the *outgoing* HTLC resolves open(os.path.join(l3.daemon.lightning_dir, TEST_NETWORK, "unhold"), "w").close() - wait_for(lambda: notifications[-1] == f'Next HTLC SENT_REMOVE_HTLC expires at block #124 (16 blocks from now) coming from peer {l1.info["id"]} (disconnected)') + wait_for(lambda: len(notifications) >= inotif + 1) + wait_for(lambda: notifications[inotif] == f'Next HTLC SENT_REMOVE_HTLC expires at block #124 (16 blocks from now) coming from peer {l1.info["id"]} (disconnected)') + inotif += 1 ret = l2.rpc.graceful(1) assert ret == {'pending_htlc_expiries': [124]}