Skip to content

Commit

Permalink
chore: added simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Jan 24, 2024
1 parent dc43ea3 commit 1436582
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions msg-socket/src/rep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ mod tests {

use futures::StreamExt;
use msg_transport::tcp::Tcp;
use msg_wire::compression::{GzipCompressor, SnappyCompressor};
use rand::Rng;

use crate::{req::ReqSocket, Authenticator, ReqOptions};
Expand Down Expand Up @@ -246,4 +247,29 @@ mod tests {
tokio::time::sleep(Duration::from_secs(1)).await;
assert_eq!(rep.stats().active_clients(), 1);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_basic_reqrep_with_compression() {
let mut rep =
RepSocket::with_options(Tcp::default(), RepOptions::default().min_compress_size(0))
.with_compressor(SnappyCompressor);

rep.bind("0.0.0.0:4445").await.unwrap();

let mut req =
ReqSocket::with_options(Tcp::default(), ReqOptions::default().min_compress_size(0))
.with_compressor(GzipCompressor::new(6));

req.connect("0.0.0.0:4445").await.unwrap();

tokio::spawn(async move {
let req = rep.next().await.unwrap();

assert_eq!(req.msg(), &Bytes::from("hello"));
req.respond(Bytes::from("world")).unwrap();
});

let res: Bytes = req.request(Bytes::from("hello")).await.unwrap();
assert_eq!(res, Bytes::from("world"));
}
}

0 comments on commit 1436582

Please sign in to comment.