diff --git a/easytier/src/tests/three_node.rs b/easytier/src/tests/three_node.rs index c2ec8125..e4c2ed74 100644 --- a/easytier/src/tests/three_node.rs +++ b/easytier/src/tests/three_node.rs @@ -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::>(); 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; } diff --git a/easytier/src/tunnel/common.rs b/easytier/src/tunnel/common.rs index e25ebbbc..3fa1d9a5 100644 --- a/easytier/src/tunnel/common.rs +++ b/easytier/src/tunnel/common.rs @@ -650,10 +650,22 @@ pub(crate) mod tests { (bps as usize, metered) } - pub async fn wait_for_condition(mut condition: F, timeout: std::time::Duration) + pub async fn wait_for_condition(condition: F, timeout: std::time::Duration) where F: FnMut() -> FRet + Send, FRet: Future, + { + 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( + mut condition: F, + timeout: std::time::Duration, + what: &str, + ) where + F: FnMut() -> FRet + Send, + FRet: Future, { 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}") } }