Skip to content

Commit 27edf15

Browse files
committed
test(mqtt): drive per-node snapshots in discovery integration tests — #898
After the per-node discovery change, discovery configs are published the first time a snapshot for a node_id arrives (not eagerly at startup). The two discovery integration tests (discovery_topics_appear_on_broker, privacy_mode_suppresses_biometric_discovery) spawned the publisher with an empty broadcast channel and never sent a snapshot, so they collected [] and failed ("missing presence discovery topic in []"). Drive snapshots for the test node_id throughout the capture window (same pattern as state_messages_published_on_snapshot_broadcast) so the per-node device's discovery lands. Verified against a local mosquitto: 3 passed.
1 parent 9ddcf0c commit 27edf15

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

v2/crates/wifi-densepose-sensing-server/tests/mqtt_integration.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,28 @@ async fn discovery_topics_appear_on_broker() {
171171
// Spawn the publisher.
172172
let cfg = make_cfg(port, false, "discovery");
173173
let builder = make_builder("inttest1");
174-
let (_tx, rx) = broadcast::channel::<VitalsSnapshot>(32);
174+
let (tx, rx) = broadcast::channel::<VitalsSnapshot>(32);
175175
let _handle = spawn(cfg, builder, rx);
176176

177+
// #898: discovery is now published per-node the first time a snapshot for
178+
// that node_id arrives (not eagerly at startup). Drive snapshots for
179+
// "inttest1" throughout the window so its device's discovery lands — same
180+
// pattern as state_messages_published_on_snapshot_broadcast.
181+
let tx_bg = tx.clone();
182+
let drive = tokio::spawn(async move {
183+
for _ in 0..60 {
184+
let _ = tx_bg.send(VitalsSnapshot {
185+
node_id: "inttest1".into(),
186+
..Default::default()
187+
});
188+
tokio::time::sleep(Duration::from_millis(200)).await;
189+
}
190+
});
191+
177192
// Drain the subscriber for up to 6 s — enough for initial discovery
178193
// + first availability publication.
179194
let msgs = collect_published(&mut sub_loop, Duration::from_secs(6)).await;
195+
drive.abort();
180196
let _ = sub.disconnect().await;
181197

182198
// Assertions: at least the presence + heart_rate + fall discovery
@@ -221,10 +237,23 @@ async fn privacy_mode_suppresses_biometric_discovery() {
221237

222238
let cfg = make_cfg(port, /* privacy_mode = */ true, "privacy");
223239
let builder = make_builder("inttest2");
224-
let (_tx, rx) = broadcast::channel::<VitalsSnapshot>(32);
240+
let (tx, rx) = broadcast::channel::<VitalsSnapshot>(32);
225241
let _handle = spawn(cfg, builder, rx);
226242

243+
// #898: per-node discovery is triggered by a snapshot for that node_id.
244+
let tx_bg = tx.clone();
245+
let drive = tokio::spawn(async move {
246+
for _ in 0..60 {
247+
let _ = tx_bg.send(VitalsSnapshot {
248+
node_id: "inttest2".into(),
249+
..Default::default()
250+
});
251+
tokio::time::sleep(Duration::from_millis(200)).await;
252+
}
253+
});
254+
227255
let msgs = collect_published(&mut sub_loop, Duration::from_secs(6)).await;
256+
drive.abort();
228257
let _ = sub.disconnect().await;
229258

230259
let topics: Vec<&str> = msgs.iter().map(|(t, _, _)| t.as_str()).collect();

0 commit comments

Comments
 (0)