From c9d9b75f761027bbef7a1fa32e90859fc9a46636 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 01:30:45 -0800 Subject: [PATCH] Tests: the held font scan test no longer hangs when its pipe is released early the_menu_family_list_now_does_not_wait_for_the_scan holds the font scan at a named pipe and released it with one blocking open for writing. That open waits for any reader and lets go only the readers already waiting. When the scan reached the pipe after the release, or ran on the test's own thread because its background thread did not start, nothing opened the pipe again and the test waited until the job timed out (a gate shard on pull request 10368 ran for over two hours). The release thread now opens the pipe for reading and writing, which does not wait for a reader, and repeats that until the scan has ended. The thread is joined after the list that waits for the scan. --- crates/text/src/tests/sysfonts.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/text/src/tests/sysfonts.rs b/crates/text/src/tests/sysfonts.rs index 261cc1c54c..246f589518 100644 --- a/crates/text/src/tests/sysfonts.rs +++ b/crates/text/src/tests/sysfonts.rs @@ -536,21 +536,28 @@ fn the_menu_family_list_now_does_not_wait_for_the_scan() { db.scan_in_background(); // The scan can't end until the pipe is opened for writing, so a list that waited for it would // hold the installed fonts. This thread lets the scan go on once the calls return, or after 10 s - // if they are still waiting, so that such a test fails instead of hanging. + // if they are still waiting, so that such a test fails instead of hanging. It opens the pipe + // for reading and writing, which doesn't wait for a reader, and repeats that until the scan has + // ended: a single open for writing waits for any reader and lets only the readers already + // waiting go, so the test hung when the scan reached the pipe later, or ran on this thread + // because its own thread didn't start. let (returned, waiting) = std::sync::mpsc::channel::<()>(); let release = pipe.clone(); let guard = std::thread::spawn(move || { let _ = waiting.recv_timeout(std::time::Duration::from_secs(10)); - // The pipe is opened and closed with nothing written. - drop(std::fs::OpenOptions::new().write(true).open(&release).unwrap()); + while !db.installed_fonts_ready() { + // The pipe is opened and closed with nothing written. + drop(std::fs::OpenOptions::new().read(true).write(true).open(&release).unwrap()); + std::thread::yield_now(); + } }); let ready = db.installed_fonts_ready(); let listed = db.menu_family_list_now(); drop(returned); - guard.join().unwrap(); assert!(!ready && !has(&listed, FAMILY), "before the scan ends, only the fonts already loaded"); // Waits for the scan. assert!(has(&db.menu_family_list(), FAMILY)); + guard.join().unwrap(); assert!(db.installed_fonts_ready()); assert_ne!(db.generation(), generation, "a menu built from the short list is built again"); assert!(has(&db.menu_family_list_now(), FAMILY));