mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-07 12:13:19 +00:00
Tests: the font menu and idle-socket tests don't fail on a busy machine
type_font_menu_lists_every_available_family compared two reads of Type › Font while a test running alongside could add a font in between, so the menu was rebuilt with one more family. It now judges a run in which the font generation held still. idle_expiry_closes_without_writing_a_line took a connection reset as a failure; on Windows the server's close of an idle connection can reach the client as one.
This commit is contained in:
@@ -58,7 +58,12 @@ fn idle_control_socket_releases_its_worker() {
|
||||
fn idle_expiry_closes_without_writing_a_line() {
|
||||
let (mut client, done, worker) = socket_fixture(short_timeouts(), |_, _| panic!("no request expected"));
|
||||
let mut got = Vec::new();
|
||||
client.read_to_end(&mut got).unwrap();
|
||||
match client.read_to_end(&mut got) {
|
||||
// On Windows the server's close can reach the client as a reset.
|
||||
Err(e) if e.kind() == std::io::ErrorKind::ConnectionReset => {}
|
||||
Ok(_) => {}
|
||||
Err(e) => panic!("reading the idle connection: {e}"),
|
||||
}
|
||||
assert_eq!(String::from_utf8_lossy(&got), "", "the app wrote to an idle connection");
|
||||
expect_socket_deadline(client, done, worker);
|
||||
}
|
||||
|
||||
@@ -13,14 +13,26 @@ fn type_font_menu_lists_every_available_family() {
|
||||
let fonts = |app: &VectorcraftApp| -> Vec<String> {
|
||||
menus::menu_entries(app).into_iter().filter(|e| e.path == ["Type", "Font"]).map(|e| e.label).collect()
|
||||
};
|
||||
let labels = fonts(&app);
|
||||
assert_eq!(labels, *FontDb::global().menu_family_list());
|
||||
let installed = FontDb::with_font_dirs(system_font_dirs());
|
||||
installed.load_system_fonts();
|
||||
let missing: Vec<String> = installed.menu_family_list().iter().filter(|f| !labels.contains(f)).cloned().collect();
|
||||
assert!(missing.is_empty(), "installed but not in Type › Font: {missing:?}");
|
||||
// The menu is built every frame, from a list built once.
|
||||
assert_eq!(fonts(&app), labels);
|
||||
// A test running alongside can add a font (and the installed fonts' scan can end), and the menu
|
||||
// is then built again: judge a run in which the fonts held still.
|
||||
for _ in 0..20 {
|
||||
let generation = FontDb::global().generation();
|
||||
let labels = fonts(&app);
|
||||
let listed = FontDb::global().menu_family_list();
|
||||
// The menu is built every frame, from a list built once.
|
||||
let again = fonts(&app);
|
||||
if FontDb::global().generation() != generation {
|
||||
continue;
|
||||
}
|
||||
assert_eq!(labels, *listed);
|
||||
let missing: Vec<String> = installed.menu_family_list().iter().filter(|f| !labels.contains(f)).cloned().collect();
|
||||
assert!(missing.is_empty(), "installed but not in Type › Font: {missing:?}");
|
||||
assert_eq!(again, labels);
|
||||
return;
|
||||
}
|
||||
panic!("the fonts kept changing");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user