From bc67ac442025c6d8c498705b0b8aabbfd7083eb6 Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 19 Jan 2024 14:56:56 -0500 Subject: [PATCH] chore: tests --- crates/torii/libp2p/src/lib.rs | 1 + crates/torii/libp2p/src/tests.rs | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/crates/torii/libp2p/src/lib.rs b/crates/torii/libp2p/src/lib.rs index 6b350e23a6..5f552d5500 100644 --- a/crates/torii/libp2p/src/lib.rs +++ b/crates/torii/libp2p/src/lib.rs @@ -1,4 +1,5 @@ pub mod client; pub mod errors; pub mod server; +mod tests; pub mod types; diff --git a/crates/torii/libp2p/src/tests.rs b/crates/torii/libp2p/src/tests.rs index 2029983a31..c4d5c0aa57 100644 --- a/crates/torii/libp2p/src/tests.rs +++ b/crates/torii/libp2p/src/tests.rs @@ -1,23 +1,21 @@ #[cfg(test)] mod test { - use super::*; - use crate::{ - client::Libp2pClient, - server::Libp2pRelay, - types::{ClientMessage, ServerMessage}, - }; + use std::error::Error; + use std::time::Duration; + use futures::StreamExt; - use std::{error::Error, time::Duration}; - use tokio::{ - self, select, - time::{self, sleep}, - }; + use tokio::time::sleep; + use tokio::{self, select}; + + use crate::client::{Libp2pClient, Message}; + use crate::server::Libp2pRelay; + use crate::types::ClientMessage; // This tests subscribing to a topic and receiving a message #[tokio::test] async fn test_client_messaging() -> Result<(), Box> { // Initialize the relay server - let relay_server = Libp2pRelay::new(Some(true), 1010)?; + let mut relay_server = Libp2pRelay::new(Some(true), 1010)?; // Give some time for the server to start up sleep(Duration::from_secs(1)).await; @@ -25,10 +23,10 @@ mod test { // Initialize the first client (listener) let mut client = Libp2pClient::new("/ip6/::1/tcp/1010".to_string())?; client.subscribe("mawmaw")?; - let (sender, mut receiver) = futures::channel::mpsc::unbounded::(); + let (sender, mut receiver) = futures::channel::mpsc::unbounded::(); tokio::spawn(async move { - relay_server.await; + relay_server.run().await; }); loop {