Skip to content

Commit

Permalink
Readd test for stream read/writing
Browse files Browse the repository at this point in the history
  • Loading branch information
Encephala committed Jun 18, 2024
1 parent 9790c58 commit c28bbd7
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions dbms/src/server/connection/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,35 @@ use tokio::{
},
};

use super::Message;
use crate::serialisation::{SerialisationManager, Serialiser};

use super::{Message, MessageBody};

// Only have one test actually open a listener,
// otherwise we'd have conflicts and stuff
// #[tokio::test]
// async fn message_read_write() {
// let test_message: Message = Message::from(b"deez nuts".as_slice());
async fn message_read_write() {
let test_message: Message = Message::from_message_body(MessageBody::Str("deez nuts".into()));

// let listener = TcpListener::bind("localhost:12345").await.unwrap();
let listener = TcpListener::bind("localhost:12345").await.unwrap();

// let mut stream = TcpStream::connect("localhost:12345").await.unwrap();
let mut stream = TcpStream::connect("localhost:12345").await.unwrap();

// let (response_stream, _) = listener.accept().await.unwrap();
let (response_stream, _) = listener.accept().await.unwrap();

// test_message.write(&mut stream).await.unwrap();
test_message.write(&mut stream, SerialisationManager(Serialiser::V2)).await.unwrap();

// let read_message = Message::read(&mut BufReader::new(response_stream)).await.unwrap();
let read_message = Message::read(
&mut BufReader::new(response_stream),
Serialiser::V2
).await.unwrap();

// assert_eq!(
// read_message.0,
// b"deez nuts"
// );
// }
if let MessageBody::Str(value) = read_message.body {
assert_eq!(
value,
"deez nuts"
);
} else {
panic!("Body wrong type");
}
}

0 comments on commit c28bbd7

Please sign in to comment.