diff --git a/src/async_resolver/state_block.rs b/src/async_resolver/state_block.rs index f778e2d4..18939ef4 100644 --- a/src/async_resolver/state_block.rs +++ b/src/async_resolver/state_block.rs @@ -204,4 +204,30 @@ mod state_block_tests { state_block.increment_current_server_index(); assert_eq!(state_block.get_current_server_index(), 0); } + + #[tokio::test] + async fn get_timestamp() { + let ip_addr = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); + let port = 53; + let key = String::from("key"); + let algorithm = String::from("algorithm"); + let udp_connection = ClientUDPConnection::new_default(ip_addr, Duration::from_secs(100)); + let tcp_connection = ClientTCPConnection::new_default(ip_addr, Duration::from_secs(100)); + let info = ServerInfo::new(ip_addr, port, key, algorithm, udp_connection, tcp_connection); + let info_clone = info.clone(); + + let info_arc_1 = Arc::new(info); + let info_arc_2 = Arc::new(info_clone); + let servers = vec![info_arc_1, info_arc_2]; + + let now = Instant::now(); + let state_block = StateBlock::new(5, 2, servers); + assert!(state_block.get_timestamp().elapsed().as_secs() < 1); + tokio::time::sleep(Duration::from_secs(1)).await; + assert!(state_block.get_timestamp().elapsed().as_secs() >= 1); + + let time_difference = now - *state_block.get_timestamp(); + println!("{:?}", time_difference); + assert!(time_difference.as_millis() < 1); + } } \ No newline at end of file