mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-04-22 16:17:23 +08:00
test: improve test_txt_public_stun_server with timeout and retry mechanism (#2014)
This commit is contained in:
+14
-11
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user