Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for drop session of same runtime #611

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions zenoh/tests/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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::<Vec<_>>();
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::<Vec<_>>();
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();
Expand Down Expand Up @@ -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;
});
}
Loading