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

stabilize liveliness API #1646

Merged
merged 17 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is the need of enabling internal_config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The liveliness test (and maybe others) uses direct access to config which is under this feature. I wanted to enable zenoh tests in stable mode so I had to detach internal_config from unstable
#1654


- 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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is the need of enabling internal_config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zenoh-ext uses direct access to config fields. Before it was hidden as the "unstable" included "internal_config"
Later I think we need to remove this feature #1655

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
Loading