Skip to content

Commit

Permalink
fixed lookup stub max tries test
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscaOrtegaG committed Nov 15, 2023
1 parent b2794a7 commit 6582cd4
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions src/resolver/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6582cd4

Please sign in to comment.