From 0c725d9408f525b1c02d762352ddf643070b367a Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sun, 12 Feb 2023 03:38:18 +0100 Subject: [PATCH] it passes --- kubi-udp/src/server.rs | 4 +++- kubi-udp/tests/test.rs | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kubi-udp/src/server.rs b/kubi-udp/src/server.rs index f358c6e..0296317 100644 --- a/kubi-udp/src/server.rs +++ b/kubi-udp/src/server.rs @@ -81,7 +81,6 @@ impl Server where S: Encode + Decode, R: Encode + Decode { addr, timeout: Instant::now(), }); - log::info!("Client with id {id} connected"); Ok(id) } fn disconnect_client_inner(&mut self, id: ClientId, reason: String) -> Result<()> { @@ -143,6 +142,7 @@ impl Server where S: Encode + Decode, R: Encode + Decode { }); } ClientPacket::Disconnect => { + log::info!("Client {id} disconnected"); self.event_queue.push_back(ServerEvent::Disconnected(id)); self.disconnect_client_inner(id, "Disconnected".into())?; }, @@ -157,6 +157,7 @@ impl Server where S: Encode + Decode, R: Encode + Decode { ClientPacket::Connect => { match self.add_client(addr) { Ok(id) => { + log::info!("Client with id {id} connected"); self.event_queue.push_back(ServerEvent::Connected(id)); self.send_to_addr(addr, IdServerPacket(None, ServerPacket::Connected(id) @@ -164,6 +165,7 @@ impl Server where S: Encode + Decode, R: Encode + Decode { }, Err(error) => { let reason = error.to_string(); + log::error!("Client connection failed: {reason}"); self.send_to_addr(addr, IdServerPacket( None, ServerPacket::Disconnected(reason) ))?; diff --git a/kubi-udp/tests/test.rs b/kubi-udp/tests/test.rs index 87aa2a3..6de54d2 100644 --- a/kubi-udp/tests/test.rs +++ b/kubi-udp/tests/test.rs @@ -40,12 +40,13 @@ fn test_connection() { server.send_message(id, STC_MSG).unwrap(); }, ServerEvent::Disconnected(id) => { - assert!(message_received, "Client {id} disconnected from the server before sending the message") + assert!(message_received, "Client {id} disconnected from the server before sending the message"); + return; }, ServerEvent::MessageReceived { from, message } => { + log::info!("server received message"); assert_eq!(message, CTS_MSG, "Received message not equal"); message_received = true; - break; }, _ => () } @@ -72,12 +73,14 @@ fn test_connection() { client.send_message(CTS_MSG).unwrap(); }, ClientEvent::Disconnected(reason) => { - assert!(message_received, "Client lost connection to the server before sending the message with reason: {reason:?}") + assert!(message_received, "Client lost connection to the server before sending the message with reason: {reason:?}"); + return; }, ClientEvent::MessageReceived(data) => { + log::info!("client received message"); assert_eq!(data, STC_MSG, "Received message not equal"); message_received = true; - break; + client.disconnect(); }, _ => () }