Skip to content

Commit

Permalink
chore: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Jan 19, 2024
1 parent 1066df8 commit bc67ac4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions crates/torii/libp2p/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod client;
pub mod errors;
pub mod server;
mod tests;
pub mod types;
26 changes: 12 additions & 14 deletions crates/torii/libp2p/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#[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<dyn Error>> {
// 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;

// 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::<ServerMessage>();
let (sender, mut receiver) = futures::channel::mpsc::unbounded::<Message>();

tokio::spawn(async move {
relay_server.await;
relay_server.run().await;
});

loop {
Expand Down

0 comments on commit bc67ac4

Please sign in to comment.