use std::time::Duration;
use zenkey_fleet::{FleetEvent, Monitor, MonitorSpec, StampProvenance, StreamItem};
mod util;
use util::timestamping_pair;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn a_stamp_we_cannot_attribute_is_unknown_and_still_names_its_stamper() {
let key = "v1/h-3fa9c2d41b7e/state/stamp/probe";
let (publisher, observer) = timestamping_pair().await;
let publisher_zid = publisher.zid();
let monitor = Monitor::start(&observer, MonitorSpec::default())
.await
.expect("monitor");
let mut events = monitor.events();
monitor.watch(key).await.expect("watch");
tokio::time::sleep(Duration::from_millis(300)).await;
let pubr = publisher
.declare_publisher(key)
.await
.expect("declare publisher");
for _ in 0..5 {
pubr.put("1").await.expect("put");
tokio::time::sleep(Duration::from_millis(40)).await;
}
let mut seen = None;
let deadline = tokio::time::Instant::now() + Duration::from_secs(5);
while tokio::time::Instant::now() < deadline {
match tokio::time::timeout(Duration::from_millis(500), events.recv()).await {
Ok(Some(StreamItem::Event(FleetEvent::Sample(s))))
if s.key == key && s.timestamp.is_some() =>
{
seen = Some((s.stamped_by, s.source));
break;
}
Ok(Some(_)) => continue,
_ => break,
}
}
monitor.stop();
let (provenance, source) = seen.expect("a stamped sample within 5s");
let provenance = provenance.expect("a stamped sample has a provenance");
assert!(
source.is_none(),
"zenoh 1.9 and 1.10 deliver no SourceInfo to a subscriber (1.10's \
eclipse-zenoh/zenoh#2563 even dropped setting it via the advanced \
API). If this now fails, SourceInfo has started riding and the \
classifier can attribute for real — update this test and O7's \
practical note rather than the code."
);
match provenance {
StampProvenance::Unattributable { stamper } => {
assert_eq!(
stamper,
zenoh::time::TimestampId::from(publisher_zid),
"the publishing session did stamp this; we simply had no \
SourceInfo on the wire with which to establish it"
);
}
other => panic!(
"with no SourceInfo the comparison cannot be made, so the only \
honest verdict is Unattributable: got {other:?}"
),
}
}