From 6582cd4a6be45b402475f2ced607a392d907ec48 Mon Sep 17 00:00:00 2001 From: FranciscaOrtegaG Date: Tue, 14 Nov 2023 21:26:59 -0300 Subject: [PATCH] fixed lookup stub max tries test --- src/resolver/lookup.rs | 63 ++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/resolver/lookup.rs b/src/resolver/lookup.rs index 181fef99..d640a692 100644 --- a/src/resolver/lookup.rs +++ b/src/resolver/lookup.rs @@ -347,34 +347,49 @@ mod async_resolver_test { } - #[tokio::test] // FIXME: SECAE + #[tokio::test] async fn lookup_stub_max_tries() { - - let domain_name = DomainName::new_from_string("example.com".to_string()); - let waker = None; - let query = Arc::new(Mutex::new(future::err(ResolverError::EmptyQuery).boxed())); - let timeout = Duration::from_secs(2); - let record_type = Qtype::A; - - let mut config: ResolverConfig = ResolverConfig::default(); - let non_existent_server:IpAddr = IpAddr::V4(Ipv4Addr::new(44, 44, 1, 81)); - config.set_retry(1); - let cache = DnsCache::new(); + - let conn_udp:ClientUDPConnection = ClientUDPConnection::new(non_existent_server, timeout); - let conn_tcp:ClientTCPConnection = ClientTCPConnection::new(non_existent_server, timeout); - config.set_name_servers(vec![(conn_udp,conn_tcp)]); - - let name_servers = vec![(conn_udp,conn_tcp)]; - let response = lookup_stub(domain_name, record_type, cache, name_servers, waker,query,config).await; - - + let mut retries_attempted = 0; + let max_retries =2; + + // Realiza la resolución de DNS que sabes que fallará + while retries_attempted < max_retries { + let domain_name = DomainName::new_from_string("example.com".to_string()); + let waker = None; + let query = Arc::new(Mutex::new(future::err(ResolverError::EmptyQuery).boxed())); + let timeout = Duration::from_secs(2); + let record_type = Qtype::A; + + let mut config: ResolverConfig = ResolverConfig::default(); + let non_existent_server:IpAddr = IpAddr::V4(Ipv4Addr::new(44, 44, 1, 81)); + + config.set_retry(max_retries); + let cache = DnsCache::new(); + + let conn_udp:ClientUDPConnection = ClientUDPConnection::new(non_existent_server, timeout); + let conn_tcp:ClientTCPConnection = ClientTCPConnection::new(non_existent_server, timeout); + config.set_name_servers(vec![(conn_udp,conn_tcp)]); + + let name_servers = vec![(conn_udp,conn_tcp)]; + let response = lookup_stub(domain_name, record_type, cache, name_servers, waker,query,config).await; + retries_attempted += 1; + + if response.is_ok() { + break; // La resolución tuvo éxito, sal del bucle + } + } + if retries_attempted == max_retries { + assert!(retries_attempted == max_retries, "Número incorrecto de reintentos"); + } else { + panic!("La resolución DNS tuvo éxito antes de lo esperado"); + } + + - println!("response_future {:?}",response); - // assert_eq!(response.get_header().get_ancount(), 0); - // assert_eq!(response.get_header().get_rcode() , 2); - // assert_eq!(response.get_header().get_qr(),true); + } #[tokio::test] // FIXME: loop