diff --git a/easytier/src/common/stun.rs b/easytier/src/common/stun.rs index 61988ffa..f77e8fd7 100644 --- a/easytier/src/common/stun.rs +++ b/easytier/src/common/stun.rs @@ -1342,6 +1342,7 @@ mod tests { common::scoped_task::ScopedTask, tunnel::{udp::UdpTunnelListener, TunnelListener}, }; + use tokio::time::{sleep, timeout}; use super::*; @@ -1399,18 +1400,20 @@ mod tests { async fn test_txt_public_stun_server() { let stun_servers = vec!["txt:stun.easytier.cn".to_string()]; let detector = UdpNatTypeDetector::new(stun_servers, 1); - for _ in 0..5 { - let ret = detector.detect_nat_type(0).await; - println!("{:#?}, {:?}", ret, ret.as_ref().map(|x| x.nat_type())); - if let Ok(resp) = ret { - assert!(!resp.stun_resps.is_empty()); - return; + timeout(Duration::from_secs(30), async { + loop { + let ret = detector.detect_nat_type(0).await; + println!("{:#?}, {:?}", ret, ret.as_ref().map(|x| x.nat_type())); + if let Ok(resp) = ret { + if !resp.stun_resps.is_empty() { + return; + } + } + sleep(Duration::from_secs(1)).await; } - } - debug_assert!( - false, - "should not reach here, stun server should be available" - ); + }) + .await + .expect("stun server should be available"); } #[tokio::test]