test(three_node): name the gate that timed out (#2749)

foreign_network_advertises_listeners_for_direct_connect waits on four
separate conditions, and wait_for_condition panics with a bare
"Timeout" from inside the helper. A red CI run therefore never says
which gate failed, which is what made the last recurrence on
fix/2739-platform-verifier hard to attribute.

Add wait_for_condition_named and use it for the four gates so the
panic names the condition. No behavior change: same polling
interval, same 10s budget.
This commit is contained in:
KKRainbow
2026-10-25 12:54:49 +08:00
committed by GitHub
parent 887c701ee8
commit 7f2e9dddf2
2 changed files with 23 additions and 6 deletions
+9 -4
View File
@@ -42,6 +42,7 @@ use crate::{
},
tunnel::common::tests::{
_tunnel_bench_netns, _tunnel_pingpong_netns_with_timeout, wait_for_condition,
wait_for_condition_named,
},
};
@@ -2930,7 +2931,7 @@ async fn foreign_network_advertises_listeners_for_direct_connect(
for (client, remote_server) in [(client_a, server_b), (client_b, server_a)] {
let client = client.get_core_instance();
let remote_server = remote_server.get_core_instance();
wait_for_condition(
wait_for_condition_named(
|| async {
remote_server
.foreign_network_snapshots(false)
@@ -2938,11 +2939,12 @@ async fn foreign_network_advertises_listeners_for_direct_connect(
.contains_key("client-net")
},
Duration::from_secs(10),
"client-net foreign network snapshot on remote server",
)
.await;
let remote_peer_id = remote_server.foreign_network_snapshots(false).await["client-net"]
.my_peer_id_for_this_network;
wait_for_condition(
wait_for_condition_named(
|| async {
client
.route_snapshots()
@@ -2951,12 +2953,13 @@ async fn foreign_network_advertises_listeners_for_direct_connect(
.any(|route| route.peer_id == remote_peer_id)
},
Duration::from_secs(10),
"route to remote peer on client",
)
.await;
// The reply is routed back by the remote server, so wait until it has
// learned the client peer in the client network as well.
let client_peer_id = client.peer_id();
wait_for_condition(
wait_for_condition_named(
|| async {
remote_server
.foreign_network_has_gateway_for_test("client-net", client_peer_id)
@@ -2964,6 +2967,7 @@ async fn foreign_network_advertises_listeners_for_direct_connect(
.unwrap_or(false)
},
Duration::from_secs(10),
"client peer learned by remote server in client-net",
)
.await;
let rpc = client
@@ -2984,7 +2988,7 @@ async fn foreign_network_advertises_listeners_for_direct_connect(
.map(url::Url::from)
.collect::<Vec<_>>();
assert_eq!(listeners, remote_server.running_listeners());
wait_for_condition(
wait_for_condition_named(
|| async {
client.peer_snapshots().await.iter().any(|peer| {
peer.peer_id == remote_peer_id
@@ -2998,6 +3002,7 @@ async fn foreign_network_advertises_listeners_for_direct_connect(
})
},
Duration::from_secs(10),
"direct connection over {protocol}",
)
.await;
}
+14 -2
View File
@@ -650,10 +650,22 @@ pub(crate) mod tests {
(bps as usize, metered)
}
pub async fn wait_for_condition<F, FRet>(mut condition: F, timeout: std::time::Duration)
pub async fn wait_for_condition<F, FRet>(condition: F, timeout: std::time::Duration)
where
F: FnMut() -> FRet + Send,
FRet: Future<Output = bool>,
{
wait_for_condition_named(condition, timeout, "condition").await
}
/// Like [`wait_for_condition`], but the panic names the gate that timed out.
pub async fn wait_for_condition_named<F, FRet>(
mut condition: F,
timeout: std::time::Duration,
what: &str,
) where
F: FnMut() -> FRet + Send,
FRet: Future<Output = bool>,
{
let now = std::time::Instant::now();
while now.elapsed() < timeout {
@@ -662,6 +674,6 @@ pub(crate) mod tests {
}
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
}
assert!(condition().await, "Timeout")
assert!(condition().await, "Timeout waiting for {what}")
}
}