From 47058f9041cfe57350ace00740656260c4cedb01 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 15:07:53 -0800 Subject: [PATCH] Tests: wait for the Scripts and Proof Setups reads with no deadline The test helpers scripts_menu::finish and proof_setup::wait called JobQueue::finish with a 10 s deadline and ignored its result. On a busy runner a read still running on a lane past that deadline left the test reading a partial listing. Both helpers now call finish(Duration::MAX), which waits on the queue's end-of-job signal with no deadline, and assert that it finished. The test that a finished read asks for a frame waited up to 10 s for the repaint. It now installs a host whose jobs wait until the test runs them (ManualJobs), runs the lane on another thread, joins it, and then checks that the frame was asked for. --- crates/ui-egui/src/dialogs/proof_setup.rs | 4 ++-- crates/ui-egui/src/scripts_menu.rs | 4 ++-- crates/ui-egui/src/tests/scripts_menu.rs | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/dialogs/proof_setup.rs b/crates/ui-egui/src/dialogs/proof_setup.rs index cb0e6981d2..20b5b52289 100644 --- a/crates/ui-egui/src/dialogs/proof_setup.rs +++ b/crates/ui-egui/src/dialogs/proof_setup.rs @@ -469,11 +469,11 @@ fn take() { } } -/// Wait for the listing under way and take it in. +/// Wait for the listing under way, however long it takes, and take it in. #[cfg(test)] pub(crate) fn wait() { if let Some(queue) = &saved().queue { - queue.finish(std::time::Duration::from_secs(10)); + assert!(queue.finish(std::time::Duration::MAX), "the listing of the Proof Setups folder could not finish"); } take(); } diff --git a/crates/ui-egui/src/scripts_menu.rs b/crates/ui-egui/src/scripts_menu.rs index c27df08742..794fc3d0a8 100644 --- a/crates/ui-egui/src/scripts_menu.rs +++ b/crates/ui-egui/src/scripts_menu.rs @@ -200,13 +200,13 @@ fn take() { } } -/// Wait for the reads under way and take them in. +/// Wait for the reads under way, however long they take, and take them in. #[cfg(test)] pub(crate) fn finish() { { let state = state(); if let Some(queue) = &state.queue { - queue.finish(Duration::from_secs(10)); + assert!(queue.finish(Duration::MAX), "the reads of the Scripts folder could not finish"); } } take(); diff --git a/crates/ui-egui/src/tests/scripts_menu.rs b/crates/ui-egui/src/tests/scripts_menu.rs index 300e0dbb32..49e78d12d0 100644 --- a/crates/ui-egui/src/tests/scripts_menu.rs +++ b/crates/ui-egui/src/tests/scripts_menu.rs @@ -3,9 +3,8 @@ //! is gone, the notes and the reads of the folder. use std::sync::Arc; -use std::time::Duration; -use craft::host::{AppInfo, Host, ThreadJobs}; +use craft::host::{AppInfo, Host, ManualJobs, ThreadJobs}; use craft::menu::Node; use serde_json::{Value, json}; use vectorcraft_engine::Session; @@ -259,13 +258,19 @@ fn a_script_that_left_the_folder_is_not_run_and_the_folder_is_read_again() { fn the_read_after_a_script_that_left_the_folder_asks_for_a_frame() { let dir = folder("gone-frame"); let mut app = app(&dir); + // The reads' lanes wait until the test runs them, so the test knows when the read has ended. + let jobs = Arc::new(ManualJobs::new()); + let held = crate::testing::ui_context(); + Host::builder(AppInfo { id: "vectorcraft", name: "VectorCraft", version: "0" }).jobs(jobs.clone()).install(&held); + app.ui_ctx = Some(held.clone()); let gone = write(&dir, "gone.js", DRAW); - read(&app); + scripts_menu::refresh(&app, &held); + scripts_menu::finish(); std::fs::remove_file(&gone).unwrap(); let (tx, frames) = std::sync::mpsc::channel(); let test = std::thread::current().id(); // The observer sees every request; the repaint callback drops one no sooner than the first read's, still pending. - ctx().set_repaint_observer(move |_| { + held.set_repaint_observer(move |_| { // The read's lane asks from a thread of its own. if std::thread::current().id() != test { let _ = tx.send(()); @@ -274,8 +279,10 @@ fn the_read_after_a_script_that_left_the_folder_asks_for_a_frame() { assert!(menus::run_ui_command(&mut app, scripts_menu::COMMAND, &json!({ "path": gone })).unwrap().is_err()); // With the app's copy of the context dropped, only the queue's wake can still ask for a frame. app.ui_ctx = None; - let asked = frames.recv_timeout(Duration::from_secs(10)); - ctx().set_repaint_observer(|_| {}); + let lanes = Arc::clone(&jobs); + assert!(std::thread::spawn(move || lanes.run_all()).join().unwrap() > 0, "the read ran on a lane"); + let asked = frames.try_recv(); + held.set_repaint_observer(|_| {}); assert_eq!(asked, Ok(()), "the finished read asks for a frame so an idle window takes it in"); scripts_menu::finish(); let _ = std::fs::remove_dir_all(dir);