mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 18:54:31 +01:00
Merge pull request #10424 from dotCooCoo/fix/menu-font-scan-test-hang
Tests: the held font scan test no longer hangs when its pipe is released early
This commit is contained in:
1 file changed
+11
-4
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user