Skip to content

Commit e88aaa8

Browse files
committed
fix(pubsub): expose events_mgr and entity on every ZSub variant
Both accessors lived on the ZSub<T, Sample, S> (queue-mode) impl, so a callback subscriber could not reach its own events manager -- the handle the rmw layer needs to install an event callback, and the only way to observe MessageLost. Neither field has anything to do with the queue. Moving them to a generic impl is what let the wiring test observe a callback subscriber's loss counter at all.
1 parent ce9f974 commit e88aaa8

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

crates/hiroz-tests/tests/message_lost.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ fn gid(n: u8) -> GidArray {
5555
g
5656
}
5757

58+
/// A CDR-encoded `Tick`, ready to hand to `Session::put`.
59+
fn payload(counter: u64) -> zenoh::bytes::ZBytes {
60+
use hiroz::msg::ZSerializer;
61+
let zbuf = <hiroz::msg::SerdeCdrSerdes<Tick>>::serialize_to_zbuf(&Tick { counter });
62+
zenoh::bytes::ZBytes::from(zbuf)
63+
}
64+
5865
/// Wait until `total_count` for `MessageLost` stops changing, then return it.
5966
fn settled_loss_count(sub_events: &Arc<Mutex<hiroz::event::EventsManager>>) -> i32 {
6067
let mut last = -1;
@@ -107,11 +114,8 @@ fn a_sequence_gap_raises_message_lost() {
107114
let publisher_gid = gid(42);
108115

109116
let put = |sn: i64, counter: u64| {
110-
let zbuf = <hiroz::msg::SerdeCdrSerdes<Tick> as hiroz::msg::ZSerializer>::serialize_to_zbuf(
111-
&Tick { counter },
112-
);
113117
session
114-
.put((*ke).clone(), zenoh::bytes::ZBytes::from(zbuf))
118+
.put((*ke).clone(), payload(counter))
115119
.attachment(Attachment::new(sn, publisher_gid))
116120
.wait()
117121
.expect("put");
@@ -169,11 +173,8 @@ fn joining_late_reports_no_loss() {
169173

170174
// First sample this subscriber ever sees from this publisher, and it is
171175
// already well into the publisher's stream.
172-
let zbuf = <hiroz::msg::SerdeCdrSerdes<Tick> as hiroz::msg::ZSerializer>::serialize_to_zbuf(
173-
&Tick { counter: 9000 },
174-
);
175176
session
176-
.put((*ke).clone(), zenoh::bytes::ZBytes::from(zbuf))
177+
.put((*ke).clone(), payload(9000))
177178
.attachment(Attachment::new(9000, gid(7)))
178179
.wait()
179180
.expect("put");

crates/hiroz/src/pubsub.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,25 @@ impl<T: ZMessage, Q, S: ZDeserializer> std::fmt::Debug for ZSub<T, Q, S> {
10121012
}
10131013
}
10141014

1015+
/// Accessors that do not depend on how the subscriber delivers.
1016+
///
1017+
/// These were on the `ZSub<T, Sample, S>` (queue-mode) impl only, so a callback
1018+
/// subscriber could not reach its own events manager — the handle the rmw layer
1019+
/// needs to install an event callback, and the only way to observe
1020+
/// [`MessageLost`](crate::event::ZenohEventType::MessageLost). Neither field has
1021+
/// anything to do with the queue.
1022+
impl<T, Q, S> ZSub<T, Q, S> {
1023+
/// The event manager this subscriber raises endpoint events on.
1024+
pub fn events_mgr(&self) -> &Arc<Mutex<EventsManager>> {
1025+
&self.events_mgr
1026+
}
1027+
1028+
/// Get a reference to the endpoint entity for this subscriber.
1029+
pub fn entity(&self) -> &EndpointEntity {
1030+
&self.entity
1031+
}
1032+
}
1033+
10151034
impl<T, S> ZSub<T, Sample, S>
10161035
where
10171036
T: ZMessage,
@@ -1043,15 +1062,6 @@ where
10431062
.ok_or_else(|| crate::error::Error::timeout(timeout))
10441063
}
10451064

1046-
pub fn events_mgr(&self) -> &Arc<Mutex<EventsManager>> {
1047-
&self.events_mgr
1048-
}
1049-
1050-
/// Get a reference to the endpoint entity for this subscriber.
1051-
pub fn entity(&self) -> &EndpointEntity {
1052-
&self.entity
1053-
}
1054-
10551065
/// Check if there are messages available in the queue
10561066
pub fn is_ready(&self) -> bool {
10571067
self.queue.as_ref().map(|q| !q.is_empty()).unwrap_or(false)

0 commit comments

Comments
 (0)