diff --git a/packages/cultmesh-rs/tests/rudp_subscription.rs b/packages/cultmesh-rs/tests/rudp_subscription.rs index ec646e47..dde78d97 100644 --- a/packages/cultmesh-rs/tests/rudp_subscription.rs +++ b/packages/cultmesh-rs/tests/rudp_subscription.rs @@ -1232,3 +1232,27 @@ fn drop_does_not_wait_for_a_reconnect_to_a_silent_peer() { assert!(started.elapsed() < Duration::from_millis(300), "{:?}", started.elapsed()); assert!(pump.upgrade().is_none(), "the thread still stops"); } + +#[test] +fn drop_sends_an_unsubscribe_for_each_live_id() { + let peer = Peer::start(); + let client = CultMeshRudpSubscriptionClient::connect(options(&peer)).unwrap(); + client.subscribe("one", vector_selection()).unwrap(); + client.subscribe("two", vector_selection()).unwrap(); + client.subscribe("gone", vector_selection()).unwrap(); + client.unsubscribe("gone").unwrap(); + for _ in 0..3 { + peer.subscribe_id(); + } + assert!(matches!(peer.next(), CultNetMessage::DatabaseUnsubscribe { subscription_id, .. } if subscription_id == "gone")); + drop(client); + let mut unsubscribed: Vec = (0..2) + .map(|_| match peer.next() { + CultNetMessage::DatabaseUnsubscribe { subscription_id, .. } => subscription_id, + other => panic!("expected an unsubscribe, got {other:?}"), + }) + .collect(); + unsubscribed.sort(); + assert_eq!(unsubscribed, ["one", "two"]); + assert!(peer.received.recv_timeout(Duration::from_millis(300)).is_err(), "nothing else is sent"); +}