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));