Browse Source

Add test for very large messages.

wip
Titouan Rigoudy 4 years ago
parent
commit
a711c51ea2
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      src/proto/connection.rs

+ 23
- 1
src/proto/connection.rs View File

@ -25,7 +25,7 @@ where
pub fn new(stream: TcpStream) -> Self { pub fn new(stream: TcpStream) -> Self {
Connection { Connection {
stream, stream,
read_buffer: BytesMut::with_capacity(4096),
read_buffer: BytesMut::new(),
phantom_read: PhantomData, phantom_read: PhantomData,
phantom_write: PhantomData, phantom_write: PhantomData,
} }
@ -80,4 +80,26 @@ mod tests {
server_task.await.unwrap(); server_task.await.unwrap();
} }
#[tokio::test]
async fn very_large_message() {
let listener = TcpListener::bind("localhost:0").await.unwrap();
let address = listener.local_addr().unwrap();
let server_task = tokio::spawn(async move {
let (stream, _peer_address) = listener.accept().await.unwrap();
let mut connection = Connection::<String, Vec<u32>>::new(stream);
assert_eq!(connection.read().await.unwrap(), "ping");
connection.write(&vec![0; 10 * 4096]).await.unwrap();
});
let stream = TcpStream::connect(address).await.unwrap();
let mut connection = Connection::<Vec<u32>, str>::new(stream);
connection.write("ping").await.unwrap();
assert_eq!(connection.read().await.unwrap(), vec![0; 10 * 4096]);
server_task.await.unwrap();
}
} }

Loading…
Cancel
Save