-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from DenisBiryukov91/feature/priority-in-sample
Expose Quality of Service settings (Priority, Congestion Control, Express) the Sample was published with
- Loading branch information
Showing
6 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Copyright (c) 2024 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use async_std::prelude::FutureExt; | ||
use async_std::task; | ||
use std::time::Duration; | ||
use zenoh::prelude::r#async::*; | ||
use zenoh::{publication::Priority, SessionDeclarations}; | ||
use zenoh_core::zasync_executor_init; | ||
|
||
const TIMEOUT: Duration = Duration::from_secs(60); | ||
const SLEEP: Duration = Duration::from_secs(1); | ||
|
||
macro_rules! ztimeout { | ||
($f:expr) => { | ||
$f.timeout(TIMEOUT).await.unwrap() | ||
}; | ||
} | ||
|
||
#[test] | ||
fn pubsub() { | ||
task::block_on(async { | ||
zasync_executor_init!(); | ||
let session1 = ztimeout!(zenoh::open(zenoh_config::peer()).res_async()).unwrap(); | ||
let session2 = ztimeout!(zenoh::open(zenoh_config::peer()).res_async()).unwrap(); | ||
|
||
let publisher1 = ztimeout!(session1 | ||
.declare_publisher("test/qos") | ||
.priority(Priority::DataHigh) | ||
.congestion_control(CongestionControl::Drop) | ||
.res()) | ||
.unwrap(); | ||
|
||
let publisher2 = ztimeout!(session1 | ||
.declare_publisher("test/qos") | ||
.priority(Priority::DataLow) | ||
.congestion_control(CongestionControl::Block) | ||
.res()) | ||
.unwrap(); | ||
|
||
let subscriber = ztimeout!(session2.declare_subscriber("test/qos").res()).unwrap(); | ||
task::sleep(SLEEP).await; | ||
|
||
ztimeout!(publisher1.put("qos").res_async()).unwrap(); | ||
let qos = ztimeout!(subscriber.recv_async()).unwrap().qos; | ||
|
||
assert_eq!(qos.priority(), Priority::DataHigh); | ||
assert_eq!(qos.congestion_control(), CongestionControl::Drop); | ||
|
||
ztimeout!(publisher2.put("qos").res_async()).unwrap(); | ||
let qos = ztimeout!(subscriber.recv_async()).unwrap().qos; | ||
|
||
assert_eq!(qos.priority(), Priority::DataLow); | ||
assert_eq!(qos.congestion_control(), CongestionControl::Block); | ||
}); | ||
} |