Skip to content

Commit

Permalink
test(socket): add reqrep tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Feb 28, 2025
1 parent ebafc3a commit 7cc1861
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions msg-socket/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod pubsub;
mod reqrep;

fn main() {}
26 changes: 26 additions & 0 deletions msg-socket/tests/it/reqrep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use bytes::Bytes;
use msg_socket::{RepSocket, ReqSocket};
use msg_transport::tcp::Tcp;
use tokio_stream::StreamExt;

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_reqrep() {
let _ = tracing_subscriber::fmt::try_init();

let mut rep = RepSocket::new(Tcp::default());
let mut req = ReqSocket::new(Tcp::default());

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

req.connect(rep.local_addr().unwrap()).await.unwrap();

tokio::spawn(async move {
while let Some(request) = rep.next().await {
let msg = request.msg().clone();
request.respond(msg).unwrap();
}
});

let response = req.request(Bytes::from_static(b"hello")).await.unwrap();
tracing::info!("Response: {:?}", response);
}

0 comments on commit 7cc1861

Please sign in to comment.