it passes

This commit is contained in:
griffi-gh 2023-02-12 03:38:18 +01:00
parent 70aaba01b0
commit 6c27d63bdf
2 changed files with 10 additions and 5 deletions

View file

@ -81,7 +81,6 @@ impl<S, R> Server<S, R> 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<S, R> Server<S, R> 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<S, R> Server<S, R> 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<S, R> Server<S, R> 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)
))?;

View file

@ -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();
},
_ => ()
}