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.
This commit is contained in:
dotCooCoo committed 2026-12-01 01:30:45 -08:00
1 parent e4eaaabd0b
commit c9d9b75f76
1 file changed
+11 -4
+11 -4
View File
@@ -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));