Skip to content

Commit

Permalink
add: get_timestamp test
Browse files Browse the repository at this point in the history
  • Loading branch information
justRkive committed Dec 3, 2024
1 parent b03b0fd commit 0c59a9c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/async_resolver/state_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0c59a9c

Please sign in to comment.