Skip to content

Commit 1b4d24f

Browse files
committed
Wait for node announcements before asserting them
Avoid assuming that a fixed sleep is enough for gossip propagation when integration tests are running concurrently. The test now waits for both peers' announcements to appear in the opposite graph before checking aliases and addresses. Co-Authored-By: HAL 9000
1 parent da9f3bc commit 1b4d24f

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
113113
#[cfg(cycle_tests)]
114114
use std::{any::Any, sync::Weak};
115115

116-
use crate::ffi::maybe_wrap;
117116
pub use balance::{BalanceDetails, LightningBalance, PendingSweepBalance};
118117
pub use bip39;
119118
pub use bitcoin;
@@ -183,6 +182,7 @@ use types::{
183182
pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, UserChannelId};
184183
pub use vss_client;
185184

185+
use crate::ffi::maybe_wrap;
186186
use crate::scoring::setup_background_pathfinding_scores_sync;
187187
use crate::wallet::FundingAmount;
188188

tests/integration_tests_rust.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,14 +1570,20 @@ async fn test_node_announcement_propagation() {
15701570
expect_channel_ready_event!(node_a, node_b.node_id());
15711571
expect_channel_ready_event!(node_b, node_a.node_id());
15721572

1573-
// Wait until node_b broadcasts a node announcement
1574-
while node_b.status().latest_node_announcement_broadcast_timestamp.is_none() {
1573+
let has_node_announcement = |node: &ldk_node::Node, node_id: bitcoin::secp256k1::PublicKey| {
1574+
node.network_graph()
1575+
.node(&NodeId::from_pubkey(&node_id))
1576+
.map_or(false, |info| info.announcement_info.is_some())
1577+
};
1578+
1579+
while node_a.status().latest_node_announcement_broadcast_timestamp.is_none()
1580+
|| node_b.status().latest_node_announcement_broadcast_timestamp.is_none()
1581+
|| !has_node_announcement(&node_b, node_a.node_id())
1582+
|| !has_node_announcement(&node_a, node_b.node_id())
1583+
{
15751584
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
15761585
}
15771586

1578-
// Sleep to make sure the node announcement propagates
1579-
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
1580-
15811587
// Get node info from the other node's perspective
15821588
let node_a_info = node_b.network_graph().node(&NodeId::from_pubkey(&node_a.node_id())).unwrap();
15831589
let node_a_announcement_info = node_a_info.announcement_info.as_ref().unwrap();

0 commit comments

Comments
 (0)