From e0ac95ee79105983a996c01c533fb269d7a3863e Mon Sep 17 00:00:00 2001 From: faumaray Date: Wed, 14 Oct 2026 18:04:34 +0300 Subject: [PATCH] Pin the order of a reconnect in the FakeLink tests The session ends the streams of a connection it replaces by sending StreamCmd::Shutdown through that connection and only then Disconnect; a link that stops reading commands at Disconnect (TsLink) relies on it. The new test connects with streams, takes the directory, connects again and asserts the old connection is given Shutdown before Disconnect. Swapping the two sends in Session::command makes it fail. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-core/tests/link_fake.rs | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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")]