mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 04:37:29 -06:00
Tests: the MCP concurrency, folder search and artboard export tests pass on a loaded machine
Squashed from #4473 onto main.
This commit is contained in:
@@ -66,9 +66,14 @@ fn rules(root: &Path) -> Rules {
|
||||
Rules { home: Some(root.join("Users/me")), user_content: vec![root.to_path_buf()], refused: vec![root.join("refused")] }
|
||||
}
|
||||
|
||||
/// The search's progress once it ended (or after 10 seconds).
|
||||
/// How long a test waits for a search to end or to read a file. The wait only ends a test whose
|
||||
/// search never ends. A machine busy with other builds can hold a walker for seconds. It is shorter than a
|
||||
/// search's default 60 s deadline, which would end a search that does not end by itself.
|
||||
const WAIT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// The search's progress once it ended (or after [`WAIT`]).
|
||||
fn wait(s: &Search) -> Progress {
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
loop {
|
||||
let p = s.progress();
|
||||
if p.end.is_some() || Instant::now() > until {
|
||||
@@ -205,14 +210,17 @@ fn the_search_ends_at_its_limits_and_when_stopped() {
|
||||
fn the_search_answers_at_its_deadline_while_a_walker_is_blocked() {
|
||||
let root = tree("blocked", &["f.ttf"]);
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let started = Instant::now();
|
||||
let s = begin(root.clone(), rules(&root), Limits { seconds: 0.2, ..Limits::default() }, 1, 1, Arc::new(Blocked(Mutex::new(rx))));
|
||||
std::thread::sleep(Duration::from_millis(300));
|
||||
let p = s.progress();
|
||||
// The search ended when it answered, and it ran no longer than the test has waited.
|
||||
let waited = started.elapsed().as_secs_f64();
|
||||
assert_eq!((p.state(), p.stopped()), ("stopped", Some("time")), "{p:?}");
|
||||
assert!(p.seconds >= 0.2 && p.seconds < 5.0, "{p:?}");
|
||||
assert!(p.seconds >= 0.2 && p.seconds <= waited, "{p:?}, {waited} s");
|
||||
let (tx2, rx2) = mpsc::channel();
|
||||
let s2 = begin(root.clone(), rules(&root), Limits::default(), 1, 1, Arc::new(Blocked(Mutex::new(rx2))));
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
while s2.progress().read == 0 && Instant::now() < until {
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
@@ -246,7 +254,7 @@ fn files_found_are_kept_as_they_are_read() {
|
||||
let root = tree("kept", &["a.ttf", "b.ttf", "c.ttf"]);
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let s = begin(root.clone(), rules(&root), Limits::default(), 1, 2, Arc::new(SecondBlocks(Mutex::new((0, rx)))));
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
while s.progress().read < 2 && Instant::now() < until {
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
@@ -426,7 +434,7 @@ fn a_search_starts_with_the_threads_left_and_fails_when_none_is() {
|
||||
assert_eq!(c.err().as_deref(), Some("the search couldn't start: try again in a moment"));
|
||||
drop((tx_a, tx_b));
|
||||
assert_eq!((wait(&a).end, wait(&b).end), (Some(End::Done), Some(End::Done)));
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
while POOL.live() > 0 && Instant::now() < until {
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
|
||||
@@ -30,9 +30,14 @@ fn session_for(root: &Path) -> Session {
|
||||
s
|
||||
}
|
||||
|
||||
/// `text.findFontFiles {}` once the search ended (10 seconds at most).
|
||||
/// How long a test waits for a search to end or to read a file. The wait only ends a test whose
|
||||
/// search never ends. A machine busy with other builds can hold a walker for seconds. It is shorter than a
|
||||
/// search's default `maxSeconds` of 60, which would end a search that does not end by itself.
|
||||
const WAIT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// `text.findFontFiles {}` once the search ended ([`WAIT`] at most).
|
||||
fn finished(s: &mut Session) -> Value {
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
loop {
|
||||
let r = s.execute("text.findFontFiles", &json!({})).unwrap();
|
||||
if r["state"] != "searching" || Instant::now() > until {
|
||||
@@ -262,7 +267,7 @@ fn stop_ends_only_the_search_it_names() {
|
||||
let search = findfiles::start(root.clone(), s.search_rules.clone(), Limits::default(), 1, 1, Arc::new(Blocked(Mutex::new(rx)))).unwrap();
|
||||
let fonts = vec![Sought { family: "A".into(), style: "Regular".into(), status: FontMatch::Missing }];
|
||||
s.font_search = Some(FontSearch { id: 7, folder: root.to_string_lossy().into_owned(), fonts, search });
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
while s.execute("text.findFontFiles", &json!({})).unwrap()["searched"]["fontFiles"] != 1 && Instant::now() < until {
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
|
||||
@@ -42,9 +42,14 @@ fn placed(s: &mut Session, path: &Path) -> u64 {
|
||||
place(s, &path.to_string_lossy()).0
|
||||
}
|
||||
|
||||
/// `links.findFiles {}` once the search ended (10 seconds at most).
|
||||
/// How long a test waits for a search to end or to read a file. The wait only ends a test whose
|
||||
/// search never ends. A machine busy with other builds can hold a walker for seconds. It is shorter than a
|
||||
/// search's default `maxSeconds` of 60, which would end a search that does not end by itself.
|
||||
const WAIT: Duration = Duration::from_secs(30);
|
||||
|
||||
/// `links.findFiles {}` once the search ended ([`WAIT`] at most).
|
||||
fn finished(s: &mut Session) -> Value {
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
loop {
|
||||
let r = s.execute("links.findFiles", &json!({})).unwrap();
|
||||
if r["state"] != "searching" || Instant::now() > until {
|
||||
@@ -206,7 +211,7 @@ fn stop_ends_only_the_search_it_names() {
|
||||
let search = findfiles::start(root.clone(), s.search_rules.clone(), Limits::default(), 1, 2, Arc::new(Blocked(Mutex::new(rx)))).unwrap();
|
||||
let links = vec![Sought { name: "a.png".into(), path: "/gone/a.png".into(), ids: vec![], size: None, hash: None }];
|
||||
s.link_search = Some(LinkSearch { id: 7, folder: root.to_string_lossy().into_owned(), links, sizes: Arc::default(), search });
|
||||
let until = Instant::now() + Duration::from_secs(10);
|
||||
let until = Instant::now() + WAIT;
|
||||
while s.execute("links.findFiles", &json!({})).unwrap()["searched"]["read"] != 1 && Instant::now() < until {
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user