Skip to content

Commit

Permalink
stabilize liveliness API (#1646)
Browse files Browse the repository at this point in the history
* Remove unstable feature flags from liveliness examples and API

* compile errors partially fixed

* compilation error fixed

* clippy fix

* cargo doc fix

* code simplified, unstable from liveliness tests removed

* explicitly enable internal_config access for tests only

* clippy fix, internal config global for liveliness test

* compile error fix

* compile fix correction

* corrected shm test

* cargo fmt

* zenoh-ext requires internal_config

* internal_config for zenohd

* liveliness functionality moved from unstable

* clippy fix

* cargo fmt
  • Loading branch information
milyin authored Dec 11, 2024
1 parent 49ed08a commit 2f27e18
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 150 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ jobs:
uses: taiki-e/install-action@nextest

- name: Run tests
run: cargo nextest run -F test --exclude zenoh-examples --exclude zenoh-plugin-example --workspace
run: cargo nextest run -F test -F internal_config --exclude zenoh-examples --exclude zenoh-plugin-example --workspace

- name: Run tests with SHM
if: ${{ matrix.os == 'macOS-latest' || matrix.os == 'windows-latest' }}
run: cargo nextest run -F test -F shared-memory -F unstable -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace
run: cargo nextest run -F test -F shared-memory -F unstable -F internal_config -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace

- name: Run tests with SHM + unixpipe
if: ${{ matrix.os == 'ubuntu-latest' }}
run: cargo nextest run -F test -F shared-memory -F unstable -F transport_unixpipe -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace
run: cargo nextest run -F test -F shared-memory -F unstable -F internal_config -F transport_unixpipe -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace

- name: Check for feature leaks
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down
3 changes: 0 additions & 3 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,14 @@ path = "examples/z_forward.rs"
[[example]]
name = "z_liveliness"
path = "examples/z_liveliness.rs"
required-features = ["unstable"]

[[example]]
name = "z_sub_liveliness"
path = "examples/z_sub_liveliness.rs"
required-features = ["unstable"]

[[example]]
name = "z_get_liveliness"
path = "examples/z_get_liveliness.rs"
required-features = ["unstable"]

[[example]]
name = "z_pub_thr"
Expand Down
2 changes: 1 addition & 1 deletion zenoh-ext/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ default = []
[dependencies]
tokio = { workspace = true, features = ["rt", "sync", "time", "macros", "io-std"] }
futures = { workspace = true }
zenoh = { workspace = true, features = ["unstable"], default-features = false }
zenoh = { workspace = true, features = ["unstable", "internal_config"], default-features = false }
clap = { workspace = true, features = ["derive"] }
zenoh-ext = { workspace = true, features = ["unstable"] }

Expand Down
2 changes: 1 addition & 1 deletion zenoh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ transport_udp = ["zenoh-transport/transport_udp"]
transport_unixsock-stream = ["zenoh-transport/transport_unixsock-stream"]
transport_ws = ["zenoh-transport/transport_ws"]
transport_vsock = ["zenoh-transport/transport_vsock"]
unstable = ["internal_config", "zenoh-keyexpr/unstable", "zenoh-config/unstable"]
unstable = ["zenoh-keyexpr/unstable", "zenoh-config/unstable"]
internal_config = []

[dependencies]
Expand Down
36 changes: 1 addition & 35 deletions zenoh/src/api/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ use crate::{
/// }
/// # }
/// ```
#[zenoh_macros::unstable]
pub struct Liveliness<'a> {
pub(crate) session: &'a Session,
}

#[zenoh_macros::unstable]
impl<'a> Liveliness<'a> {
/// Create a [`LivelinessToken`](LivelinessToken) for the given key expression.
///
Expand All @@ -120,7 +117,6 @@ impl<'a> Liveliness<'a> {
/// .unwrap();
/// # }
/// ```
#[zenoh_macros::unstable]
pub fn declare_token<'b, TryIntoKeyExpr>(
&self,
key_expr: TryIntoKeyExpr,
Expand Down Expand Up @@ -157,7 +153,6 @@ impl<'a> Liveliness<'a> {
/// }
/// # }
/// ```
#[zenoh_macros::unstable]
pub fn declare_subscriber<'b, TryIntoKeyExpr>(
&self,
key_expr: TryIntoKeyExpr,
Expand Down Expand Up @@ -194,7 +189,6 @@ impl<'a> Liveliness<'a> {
/// }
/// # }
/// ```
#[zenoh_macros::unstable]
pub fn get<'b, TryIntoKeyExpr>(
&self,
key_expr: TryIntoKeyExpr,
Expand All @@ -205,7 +199,7 @@ impl<'a> Liveliness<'a> {
{
let key_expr = key_expr.try_into().map_err(Into::into);
let timeout = {
let conf = self.session.0.runtime.config().lock();
let conf = &self.session.0.runtime.config().lock().0;
Duration::from_millis(unwrap_or_default!(conf.queries_default_timeout()))
};
LivelinessGetBuilder {
Expand Down Expand Up @@ -233,19 +227,16 @@ impl<'a> Liveliness<'a> {
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
pub struct LivelinessTokenBuilder<'a, 'b> {
pub(crate) session: &'a Session,
pub(crate) key_expr: ZResult<KeyExpr<'b>>,
}

#[zenoh_macros::unstable]
impl Resolvable for LivelinessTokenBuilder<'_, '_> {
type To = ZResult<LivelinessToken>;
}

#[zenoh_macros::unstable]
impl Wait for LivelinessTokenBuilder<'_, '_> {
#[inline]
fn wait(self) -> <Self as Resolvable>::To {
Expand All @@ -262,7 +253,6 @@ impl Wait for LivelinessTokenBuilder<'_, '_> {
}
}

#[zenoh_macros::unstable]
impl IntoFuture for LivelinessTokenBuilder<'_, '_> {
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;
Expand Down Expand Up @@ -296,7 +286,6 @@ impl IntoFuture for LivelinessTokenBuilder<'_, '_> {
/// .unwrap();
/// # }
/// ```
#[zenoh_macros::unstable]
#[must_use = "Liveliness tokens will be immediately dropped and undeclared if not bound to a variable"]
#[derive(Debug)]
pub struct LivelinessToken {
Expand All @@ -323,22 +312,18 @@ pub struct LivelinessToken {
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[zenoh_macros::unstable]
pub struct LivelinessTokenUndeclaration(LivelinessToken);

#[zenoh_macros::unstable]
impl Resolvable for LivelinessTokenUndeclaration {
type To = ZResult<()>;
}

#[zenoh_macros::unstable]
impl Wait for LivelinessTokenUndeclaration {
fn wait(mut self) -> <Self as Resolvable>::To {
self.0.undeclare_impl()
}
}

#[zenoh_macros::unstable]
impl IntoFuture for LivelinessTokenUndeclaration {
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;
Expand All @@ -348,7 +333,6 @@ impl IntoFuture for LivelinessTokenUndeclaration {
}
}

#[zenoh_macros::unstable]
impl LivelinessToken {
/// Undeclare the [`LivelinessToken`].
///
Expand Down Expand Up @@ -379,7 +363,6 @@ impl LivelinessToken {
}
}

#[zenoh_macros::unstable]
impl UndeclarableSealed<()> for LivelinessToken {
type Undeclaration = LivelinessTokenUndeclaration;

Expand All @@ -388,7 +371,6 @@ impl UndeclarableSealed<()> for LivelinessToken {
}
}

#[zenoh_macros::unstable]
impl Drop for LivelinessToken {
fn drop(&mut self) {
if self.undeclare_on_drop {
Expand All @@ -415,7 +397,6 @@ impl Drop for LivelinessToken {
/// # }
/// ```
#[must_use = "Resolvables do nothing unless you resolve them using `.await` or `zenoh::Wait::wait`"]
#[zenoh_macros::unstable]
#[derive(Debug)]
pub struct LivelinessSubscriberBuilder<'a, 'b, Handler, const BACKGROUND: bool = false> {
pub session: &'a Session,
Expand All @@ -424,7 +405,6 @@ pub struct LivelinessSubscriberBuilder<'a, 'b, Handler, const BACKGROUND: bool =
pub history: bool,
}

#[zenoh_macros::unstable]
impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// Receive the samples for this liveliness subscription with a callback.
///
Expand All @@ -443,7 +423,6 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// # }
/// ```
#[inline]
#[zenoh_macros::unstable]
pub fn callback<F>(self, callback: F) -> LivelinessSubscriberBuilder<'a, 'b, Callback<Sample>>
where
F: Fn(Sample) + Send + Sync + 'static,
Expand Down Expand Up @@ -472,7 +451,6 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// # }
/// ```
#[inline]
#[zenoh_macros::unstable]
pub fn callback_mut<F>(
self,
callback: F,
Expand Down Expand Up @@ -503,7 +481,6 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// # }
/// ```
#[inline]
#[zenoh_macros::unstable]
pub fn with<Handler>(self, handler: Handler) -> LivelinessSubscriberBuilder<'a, 'b, Handler>
where
Handler: IntoHandler<Sample>,
Expand Down Expand Up @@ -556,14 +533,12 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, Callback<Sample>> {

impl<Handler, const BACKGROUND: bool> LivelinessSubscriberBuilder<'_, '_, Handler, BACKGROUND> {
#[inline]
#[zenoh_macros::unstable]
pub fn history(mut self, history: bool) -> Self {
self.history = history;
self
}
}

#[zenoh_macros::unstable]
impl<Handler> Resolvable for LivelinessSubscriberBuilder<'_, '_, Handler>
where
Handler: IntoHandler<Sample> + Send,
Expand All @@ -572,13 +547,11 @@ where
type To = ZResult<Subscriber<Handler::Handler>>;
}

#[zenoh_macros::unstable]
impl<Handler> Wait for LivelinessSubscriberBuilder<'_, '_, Handler>
where
Handler: IntoHandler<Sample> + Send,
Handler::Handler: Send,
{
#[zenoh_macros::unstable]
fn wait(self) -> <Self as Resolvable>::To {
use super::subscriber::SubscriberKind;

Expand Down Expand Up @@ -606,7 +579,6 @@ where
}
}

#[zenoh_macros::unstable]
impl<Handler> IntoFuture for LivelinessSubscriberBuilder<'_, '_, Handler>
where
Handler: IntoHandler<Sample> + Send,
Expand All @@ -615,20 +587,16 @@ where
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;

#[zenoh_macros::unstable]
fn into_future(self) -> Self::IntoFuture {
std::future::ready(self.wait())
}
}

#[zenoh_macros::unstable]
impl Resolvable for LivelinessSubscriberBuilder<'_, '_, Callback<Sample>, true> {
type To = ZResult<()>;
}

#[zenoh_macros::unstable]
impl Wait for LivelinessSubscriberBuilder<'_, '_, Callback<Sample>, true> {
#[zenoh_macros::unstable]
fn wait(self) -> <Self as Resolvable>::To {
self.session.0.declare_liveliness_subscriber_inner(
&self.key_expr?,
Expand All @@ -640,12 +608,10 @@ impl Wait for LivelinessSubscriberBuilder<'_, '_, Callback<Sample>, true> {
}
}

#[zenoh_macros::unstable]
impl IntoFuture for LivelinessSubscriberBuilder<'_, '_, Callback<Sample>, true> {
type Output = <Self as Resolvable>::To;
type IntoFuture = Ready<<Self as Resolvable>::To>;

#[zenoh_macros::unstable]
fn into_future(self) -> Self::IntoFuture {
std::future::ready(self.wait())
}
Expand Down
1 change: 0 additions & 1 deletion zenoh/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub(crate) mod encoding;
pub(crate) mod handlers;
pub(crate) mod info;
pub(crate) mod key_expr;
#[cfg(feature = "unstable")]
pub(crate) mod liveliness;
#[cfg(feature = "plugins")]
pub(crate) mod loader;
Expand Down
1 change: 0 additions & 1 deletion zenoh/src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ impl From<Reply> for Result<Sample, ReplyError> {
}
}

#[cfg(feature = "unstable")]
pub(crate) struct LivelinessQueryState {
pub(crate) callback: Callback<Reply>,
}
Expand Down
Loading

0 comments on commit 2f27e18

Please sign in to comment.