mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-26 00:38:44 -06:00
it passes
This commit is contained in:
parent
70aaba01b0
commit
6c27d63bdf
|
@ -81,7 +81,6 @@ impl<S, R> Server<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||||
addr,
|
addr,
|
||||||
timeout: Instant::now(),
|
timeout: Instant::now(),
|
||||||
});
|
});
|
||||||
log::info!("Client with id {id} connected");
|
|
||||||
Ok(id)
|
Ok(id)
|
||||||
}
|
}
|
||||||
fn disconnect_client_inner(&mut self, id: ClientId, reason: String) -> Result<()> {
|
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 => {
|
ClientPacket::Disconnect => {
|
||||||
|
log::info!("Client {id} disconnected");
|
||||||
self.event_queue.push_back(ServerEvent::Disconnected(id));
|
self.event_queue.push_back(ServerEvent::Disconnected(id));
|
||||||
self.disconnect_client_inner(id, "Disconnected".into())?;
|
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 => {
|
ClientPacket::Connect => {
|
||||||
match self.add_client(addr) {
|
match self.add_client(addr) {
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
|
log::info!("Client with id {id} connected");
|
||||||
self.event_queue.push_back(ServerEvent::Connected(id));
|
self.event_queue.push_back(ServerEvent::Connected(id));
|
||||||
self.send_to_addr(addr,
|
self.send_to_addr(addr,
|
||||||
IdServerPacket(None, ServerPacket::Connected(id)
|
IdServerPacket(None, ServerPacket::Connected(id)
|
||||||
|
@ -164,6 +165,7 @@ impl<S, R> Server<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||||
},
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
let reason = error.to_string();
|
let reason = error.to_string();
|
||||||
|
log::error!("Client connection failed: {reason}");
|
||||||
self.send_to_addr(addr, IdServerPacket(
|
self.send_to_addr(addr, IdServerPacket(
|
||||||
None, ServerPacket::Disconnected(reason)
|
None, ServerPacket::Disconnected(reason)
|
||||||
))?;
|
))?;
|
||||||
|
|
|
@ -40,12 +40,13 @@ fn test_connection() {
|
||||||
server.send_message(id, STC_MSG).unwrap();
|
server.send_message(id, STC_MSG).unwrap();
|
||||||
},
|
},
|
||||||
ServerEvent::Disconnected(id) => {
|
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 } => {
|
ServerEvent::MessageReceived { from, message } => {
|
||||||
|
log::info!("server received message");
|
||||||
assert_eq!(message, CTS_MSG, "Received message not equal");
|
assert_eq!(message, CTS_MSG, "Received message not equal");
|
||||||
message_received = true;
|
message_received = true;
|
||||||
break;
|
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
@ -72,12 +73,14 @@ fn test_connection() {
|
||||||
client.send_message(CTS_MSG).unwrap();
|
client.send_message(CTS_MSG).unwrap();
|
||||||
},
|
},
|
||||||
ClientEvent::Disconnected(reason) => {
|
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) => {
|
ClientEvent::MessageReceived(data) => {
|
||||||
|
log::info!("client received message");
|
||||||
assert_eq!(data, STC_MSG, "Received message not equal");
|
assert_eq!(data, STC_MSG, "Received message not equal");
|
||||||
message_received = true;
|
message_received = true;
|
||||||
break;
|
client.disconnect();
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue