diff --git a/src/async_resolver/state_block.rs b/src/async_resolver/state_block.rs index f6bd37f0..f620b790 100644 --- a/src/async_resolver/state_block.rs +++ b/src/async_resolver/state_block.rs @@ -155,8 +155,28 @@ mod state_block_tests { } } + #[test] + fn decrement_work_counter_error() { + 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_arc = Arc::new(info); + let servers = vec![info_arc]; + let mut state_block = StateBlock::new(1, 2, servers); + assert_eq!(state_block.get_work_counter(), 1); + if let Ok(_) = state_block.decrement_work_counter() { + assert_eq!(state_block.get_work_counter(), 0); + } + if let Err(ResolverError::RetriesLimitExceeded) = state_block.decrement_work_counter() { + assert_eq!(state_block.get_work_counter(), 0); + } + } } \ No newline at end of file