From c5bb74ffcbd5def3aee8474905c09defb4b49f28 Mon Sep 17 00:00:00 2001 From: faumaray Date: Sun, 25 Oct 2026 03:26:33 +0300 Subject: [PATCH] Ask the file list one question at a time in the server-features test the_features_of_a_server_are_the_hosts_narrowed_by_the_servers_list asked for the lobby's file list every 20 ms until the answer was the one it wanted. The bus holds 16 events, so on a busy machine the answers fell behind it (and behind the host's work) and the one that counted was lost in the backlog, or an answer to a question asked before the host narrowed what it offers was taken for one asked after. A helper, ask_files_until, now asks one question and reads the bus until that question's answer comes, then asks the next only if the answer was not the one wanted. Every question is answered before the next is asked, so those asked after the update is pushed are the ones the update can refuse; nothing has to be told apart by number, and nothing is waited out by the clock. The test checks that the answer after the server lifted its list came from the host. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-core/src/link/tests.rs | 86 +++++++++++++++------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/crates/voelin-core/src/link/tests.rs b/crates/voelin-core/src/link/tests.rs index 711cce5..2c6d408 100644 --- a/crates/voelin-core/src/link/tests.rs +++ b/crates/voelin-core/src/link/tests.rs @@ -2184,12 +2184,46 @@ async fn event_of( .await } +/// Asks for the file list of the lobby until the answer is one `wanted` takes, +/// one question at a time: the next goes out only when the last is answered. +/// Asked every few milliseconds instead, the answers fell behind the 16 +/// events the bus holds (and the host's work), and the one that counted was +/// lost in the backlog. +async fn ask_files_until( + cmd_tx: &mpsc::UnboundedSender, + bus: &mut broadcast::Receiver, + request: &mut crate::files::RequestId, + wanted: impl Fn(&Result, String>) -> bool, +) { + within("the file list to be answered as wanted", async { + loop { + *request += 1; + let dir = remote(10, None, "/"); + cmd_tx.send(LinkCmd::ListFiles { request: *request, dir }).ok()?; + let result = loop { + match bus.recv().await { + Ok(Event::FileList { request: answered, result, .. }) if answered == *request => { + break result; + } + Ok(_) | Err(broadcast::error::RecvError::Lagged(_)) => {} + Err(broadcast::error::RecvError::Closed) => return None, + } + }; + if wanted(&result) { + return Some(()); + } + tokio::time::sleep(Duration::from_millis(20)).await; + } + }) + .await; +} + /// `Server.features` narrows what the host offers (protocol 1.3, /// `docs/session-seam.md` 4.7), and a `HostUpdate` changes what is narrowed. #[tokio::test(flavor = "multi_thread")] async fn the_features_of_a_server_are_the_hosts_narrowed_by_the_servers_list() { use v1::entity::Kind; - use voelin_proto::test_util::{FakeConnector, eventually}; + use voelin_proto::test_util::FakeConnector; let connector = FakeConnector::new(); let host = connector.host(); @@ -2241,55 +2275,27 @@ async fn the_features_of_a_server_are_the_hosts_narrowed_by_the_servers_list() { }) .count() }; - let ask = |request| { - let dir = remote(10, None, "/"); - cmd_tx.send(LinkCmd::ListFiles { request, dir }).unwrap(); - }; let refusal = "not offered by this server: files"; - let refused = - |event: &Event| matches!(event, Event::FileList { result: Err(why), .. } if why == refusal); + let refused = |result: &Result, String>| { + matches!(result, Err(why) if why == refusal) + }; + let mut request = 0; // Refused here: nothing reaches the host. - ask(1); - loop { - let event = within("the refusal", async { bus.recv().await.ok() }).await; - if refused(&event) { - break; - } - } + ask_files_until(&cmd_tx, &mut bus, &mut request, refused).await; assert_eq!(file_lists(), 0); // The server lifts its list (an empty one keeps all the host's): files work. put_server(&[]); - let mut request = 1; - eventually(WAIT, "a file list to reach the host", || { - request += 1; - ask(request); - file_lists() > 0 - }) - .await; + ask_files_until(&cmd_tx, &mut bus, &mut request, |result| !refused(result)).await; + assert!(file_lists() > 0, "the answer did not come from the host"); - // The host narrows what it offers this user. A refusal counts only for a - // request made after the update: the earlier ones were answered by the host's - // wider set (or, before the server lifted its list, refused for that). + // The host narrows what it offers this user. Every question is answered + // before the next is asked, so those asked from here on are the ones the + // update can refuse; the earlier ones were answered by the host's wider set. let update = v1::HostUpdate { features: vec!["voice".into(), "chat".into()], limits: None }; handle.push(v1::Push { body: Some(v1::push::Body::HostUpdate(update)) }).unwrap(); - let after = request; - within("the narrower set to apply", async { - loop { - request += 1; - ask(request); - tokio::time::sleep(Duration::from_millis(20)).await; - while let Ok(event) = bus.try_recv() { - if matches!(&event, Event::FileList { request, .. } if *request > after) - && refused(&event) - { - return Some(()); - } - } - } - }) - .await; + ask_files_until(&cmd_tx, &mut bus, &mut request, refused).await; } /// A port that is no port is refused in words, not dropped: the connection