test: improve test_txt_public_stun_server with timeout and retry mechanism (#2014)

This commit is contained in:
Luna Yao
2026-03-26 02:32:07 +01:00
committed by GitHub
parent e2684a93de
commit 8e4dc508bb
+14 -11
View File
@@ -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]