diff --git a/crates/voelin-core/tests/link_fake.rs b/crates/voelin-core/tests/link_fake.rs index 59f08ff..101f5af 100644 --- a/crates/voelin-core/tests/link_fake.rs +++ b/crates/voelin-core/tests/link_fake.rs @@ -381,6 +381,35 @@ async fn commands_reach_the_link() { assert!(matches!(with_streams.cmd().await, LinkCmd::Disconnect)); } +/// A reconnect ends the streams of the connection it replaces through that +/// connection, before the connection itself: the old link is given +/// `StreamCmd::Shutdown` and only then `Disconnect`. A link that ends its +/// connection on `Disconnect` (the TeamSpeak one stops reading commands +/// there) relies on this order for the streams to hear of their end. +#[tokio::test(flavor = "multi_thread")] +async fn a_reconnect_shuts_the_streams_down_before_the_old_connection() { + let mut h = Harness::start(); + let mut old = h.connect().await; + old.play([ + connected(true), + LinkEvent::Presence(Box::new(presence())), + LinkEvent::OwnChannel(GAMES), + ]); + h.state(|s| s.own_channel == Some(GAMES)).await; + let LinkCmd::Stream(StreamCmd::Directory(directory)) = old.cmd().await else { + panic!("the stream directory") + }; + assert!(directory.is_empty()); + + // Connecting again replaces the connection. + let _new = h.connect().await; + let LinkCmd::Stream(StreamCmd::Shutdown(reason)) = old.cmd().await else { + panic!("the streams end first") + }; + assert_eq!(reason, "voice reconnecting"); + assert!(matches!(old.cmd().await, LinkCmd::Disconnect)); +} + /// A message we send is stored at once; the server's copy of it merges /// into the same row, and is shown (once). #[tokio::test(flavor = "multi_thread")]