diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index c2cec7c627..63af0a8627 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -17,6 +17,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::time::Duration; use zenoh::prelude::r#async::*; +use zenoh::runtime::Runtime; use zenoh_core::zasync_executor_init; const TIMEOUT: Duration = Duration::from_secs(60); @@ -71,6 +72,29 @@ async fn open_session_multicast(endpoint01: &str, endpoint02: &str) -> (Session, (peer01, peer02) } +async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime) { + // Open the sessions + let mut config = config::peer(); + config.listen.endpoints = endpoints + .iter() + .map(|e| e.parse().unwrap()) + .collect::>(); + config.scouting.multicast.set_enabled(Some(false)).unwrap(); + println!("[ ][01a] Creating peer01 session runtime: {:?}", endpoints); + let peer01 = Runtime::new(config).await.unwrap(); + + let mut config = config::peer(); + config.connect.endpoints = endpoints + .iter() + .map(|e| e.parse().unwrap()) + .collect::>(); + config.scouting.multicast.set_enabled(Some(false)).unwrap(); + println!("[ ][02a] Creating peer02 session runtime: {:?}", endpoints); + let peer02 = Runtime::new(config).await.unwrap(); + + (peer01, peer02) +} + async fn close_session(peer01: Session, peer02: Session) { println!("[ ][01d] Closing peer02 session"); ztimeout!(peer01.close().res_async()).unwrap(); @@ -211,3 +235,21 @@ fn zenoh_session_multicast() { close_session(peer01, peer02).await; }); } + +#[test] +fn zenoh_session_runtime_init() { + task::block_on(async { + zasync_executor_init!(); + let (r1, r2) = open_session_unicast_runtime(&["tcp/127.0.1:17447"]).await; + println!("[RI][02a] Creating peer01 session from runtime 1"); + let peer01 = zenoh::init(r1.clone()).res_async().await.unwrap(); + println!("[RI][02b] Creating peer02 session from runtime 2"); + let peer02 = zenoh::init(r2.clone()).res_async().await.unwrap(); + println!("[RI][02c] Creating peer01a session from runtime 1"); + let peer01a = zenoh::init(r2.clone()).res_async().await.unwrap(); + test_session_pubsub(&peer01, &peer02, Reliability::Reliable).await; + println!("[RI][02d] Closing peer02a session"); + std::mem::drop(peer01a); + test_session_pubsub(&peer01, &peer02, Reliability::Reliable).await; + }); +}