Skip to content

Commit

Permalink
Revert the use of Result
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanYuYuan committed Jan 26, 2024
1 parent a268535 commit 3357fef
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions zenoh/tests/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! ztimeout {
}

#[cfg(feature = "unstable")]
async fn create_session_pair(locator: &str) -> Result<(Session, Session)> {
async fn create_session_pair(locator: &str) -> (Session, Session) {
let config1 = {
let mut config = zenoh::config::peer();
config.scouting.multicast.set_enabled(Some(false)).unwrap();
Expand All @@ -39,11 +39,11 @@ async fn create_session_pair(locator: &str) -> Result<(Session, Session)> {
.unwrap();
config
};
let config2 = zenoh::config::client([Locator::from_str(locator)?]);
let config2 = zenoh::config::client([Locator::from_str(locator).unwrap()]);

let session1 = ztimeout!(zenoh::open(config1).res_async())?;
let session2 = ztimeout!(zenoh::open(config2).res_async())?;
Ok((session1, session2))
let session1 = ztimeout!(zenoh::open(config1).res_async()).unwrap();
let session2 = ztimeout!(zenoh::open(config2).res_async()).unwrap();
(session1, session2)
}

#[cfg(feature = "unstable")]
Expand All @@ -54,55 +54,58 @@ fn zenoh_matching_status_any() -> Result<()> {
task::block_on(async {
zasync_executor_init!();

let (session1, session2) = create_session_pair("tcp/127.0.0.1:18001").await?;
let (session1, session2) = create_session_pair("tcp/127.0.0.1:18001").await;

let publisher1 = ztimeout!(session1
.declare_publisher("zenoh_matching_status_any_test")
.allowed_destination(Locality::Any)
.res_async())?;
.res_async())
.unwrap();

let matching_listener = ztimeout!(publisher1.matching_listener().res_async())?;
let matching_listener = ztimeout!(publisher1.matching_listener().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

let sub = ztimeout!(session1
.declare_subscriber("zenoh_matching_status_any_test")
.res_async())?;
.res_async())
.unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(matching_status.matching_subscribers());

ztimeout!(sub.undeclare().res_async())?;
ztimeout!(sub.undeclare().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

let sub = ztimeout!(session2
.declare_subscriber("zenoh_matching_status_any_test")
.res_async())?;
.res_async())
.unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(matching_status.matching_subscribers());

ztimeout!(sub.undeclare().res_async())?;
ztimeout!(sub.undeclare().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());
Ok(())
})
Expand All @@ -116,57 +119,60 @@ fn zenoh_matching_status_remote() -> Result<()> {
task::block_on(async {
zasync_executor_init!();

let session1 = ztimeout!(zenoh::open(config::peer()).res_async())?;
let session1 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap();

let session2 = ztimeout!(zenoh::open(config::peer()).res_async())?;
let session2 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap();

let publisher1 = ztimeout!(session1
.declare_publisher("zenoh_matching_status_remote_test")
.allowed_destination(Locality::Remote)
.res_async())?;
.res_async())
.unwrap();

let matching_listener = ztimeout!(publisher1.matching_listener().res_async())?;
let matching_listener = ztimeout!(publisher1.matching_listener().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

let sub = ztimeout!(session1
.declare_subscriber("zenoh_matching_status_remote_test")
.res_async())?;
.res_async())
.unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

ztimeout!(sub.undeclare().res_async())?;
ztimeout!(sub.undeclare().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

let sub = ztimeout!(session2
.declare_subscriber("zenoh_matching_status_remote_test")
.res_async())?;
.res_async())
.unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(matching_status.matching_subscribers());

ztimeout!(sub.undeclare().res_async())?;
ztimeout!(sub.undeclare().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

Ok(())
Expand All @@ -181,57 +187,60 @@ fn zenoh_matching_status_local() -> Result<()> {
task::block_on(async {
zasync_executor_init!();

let session1 = ztimeout!(zenoh::open(config::peer()).res_async())?;
let session1 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap();

let session2 = ztimeout!(zenoh::open(config::peer()).res_async())?;
let session2 = ztimeout!(zenoh::open(config::peer()).res_async()).unwrap();

let publisher1 = ztimeout!(session1
.declare_publisher("zenoh_matching_status_local_test")
.allowed_destination(Locality::SessionLocal)
.res_async())?;
.res_async())
.unwrap();

let matching_listener = ztimeout!(publisher1.matching_listener().res_async())?;
let matching_listener = ztimeout!(publisher1.matching_listener().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

let sub = ztimeout!(session1
.declare_subscriber("zenoh_matching_status_local_test")
.res_async())?;
.res_async())
.unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(true));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(matching_status.matching_subscribers());

ztimeout!(sub.undeclare().res_async())?;
ztimeout!(sub.undeclare().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.ok().map(|s| s.matching_subscribers()) == Some(false));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

let sub = ztimeout!(session2
.declare_subscriber("zenoh_matching_status_local_test")
.res_async())?;
.res_async())
.unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

ztimeout!(sub.undeclare().res_async())?;
ztimeout!(sub.undeclare().res_async()).unwrap();

let received_status = matching_listener.recv_timeout(RECV_TIMEOUT);
assert!(received_status.err() == Some(RecvTimeoutError::Timeout));

let matching_status = ztimeout!(publisher1.matching_status().res_async())?;
let matching_status = ztimeout!(publisher1.matching_status().res_async()).unwrap();
assert!(!matching_status.matching_subscribers());

Ok(())
Expand Down

0 comments on commit 3357fef

Please sign in to comment.