mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
test: improve test_txt_public_stun_server with timeout and retry mechanism (#2014)
This commit is contained in:
@@ -1342,6 +1342,7 @@ mod tests {
|
|||||||
common::scoped_task::ScopedTask,
|
common::scoped_task::ScopedTask,
|
||||||
tunnel::{udp::UdpTunnelListener, TunnelListener},
|
tunnel::{udp::UdpTunnelListener, TunnelListener},
|
||||||
};
|
};
|
||||||
|
use tokio::time::{sleep, timeout};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@@ -1399,18 +1400,20 @@ mod tests {
|
|||||||
async fn test_txt_public_stun_server() {
|
async fn test_txt_public_stun_server() {
|
||||||
let stun_servers = vec!["txt:stun.easytier.cn".to_string()];
|
let stun_servers = vec!["txt:stun.easytier.cn".to_string()];
|
||||||
let detector = UdpNatTypeDetector::new(stun_servers, 1);
|
let detector = UdpNatTypeDetector::new(stun_servers, 1);
|
||||||
for _ in 0..5 {
|
timeout(Duration::from_secs(30), async {
|
||||||
|
loop {
|
||||||
let ret = detector.detect_nat_type(0).await;
|
let ret = detector.detect_nat_type(0).await;
|
||||||
println!("{:#?}, {:?}", ret, ret.as_ref().map(|x| x.nat_type()));
|
println!("{:#?}, {:?}", ret, ret.as_ref().map(|x| x.nat_type()));
|
||||||
if let Ok(resp) = ret {
|
if let Ok(resp) = ret {
|
||||||
assert!(!resp.stun_resps.is_empty());
|
if !resp.stun_resps.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug_assert!(
|
sleep(Duration::from_secs(1)).await;
|
||||||
false,
|
}
|
||||||
"should not reach here, stun server should be available"
|
})
|
||||||
);
|
.await
|
||||||
|
.expect("stun server should be available");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user