From b03b0fd0b09fbdc82589e02ea1081c430eb96b29 Mon Sep 17 00:00:00 2001 From: Katia Date: Tue, 3 Dec 2024 14:36:56 +0900 Subject: [PATCH] add: increment current server test --- src/async_resolver/state_block.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/async_resolver/state_block.rs b/src/async_resolver/state_block.rs index f620b790..f778e2d4 100644 --- a/src/async_resolver/state_block.rs +++ b/src/async_resolver/state_block.rs @@ -179,4 +179,29 @@ mod state_block_tests { assert_eq!(state_block.get_work_counter(), 0); } } + + #[test] + fn increment_current_server_index() { + 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 mut state_block = StateBlock::new(5, 2, servers); + assert_eq!(state_block.get_current_server_index(), 0); + + state_block.increment_current_server_index(); + assert_eq!(state_block.get_current_server_index(), 1); + + state_block.increment_current_server_index(); + assert_eq!(state_block.get_current_server_index(), 0); + } } \ No newline at end of file