mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 09:21:55 +01:00
Merge pull request #9816 from dotCooCoo/fix/jobqueue-finish-tests
Tests: wait for the Scripts and Proof Setups reads with no deadline
This commit is contained in:
3 files changed
+17
-10
No files matched your search
@@ -469,11 +469,11 @@ fn take() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wait for the listing under way and take it in.
|
||||
/// Wait for the listing under way, however long it takes, and take it in.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn wait() {
|
||||
if let Some(queue) = &saved().queue {
|
||||
queue.finish(std::time::Duration::from_secs(10));
|
||||
assert!(queue.finish(std::time::Duration::MAX), "the listing of the Proof Setups folder could not finish");
|
||||
}
|
||||
take();
|
||||
}
|
||||
|
||||
@@ -201,13 +201,13 @@ fn take() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wait for the reads under way and take them in.
|
||||
/// Wait for the reads under way, however long they take, and take them in.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn finish() {
|
||||
{
|
||||
let state = state();
|
||||
if let Some(queue) = &state.queue {
|
||||
queue.finish(Duration::from_secs(10));
|
||||
assert!(queue.finish(Duration::MAX), "the reads of the Scripts folder could not finish");
|
||||
}
|
||||
}
|
||||
take();
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
//! is gone, the notes and the reads of the folder.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use craft::host::{AppInfo, Host, ThreadJobs};
|
||||
use craft::host::{AppInfo, Host, ManualJobs, ThreadJobs};
|
||||
use craft::menu::Node;
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_engine::Session;
|
||||
@@ -260,13 +259,19 @@ fn a_script_that_left_the_folder_is_not_run_and_the_folder_is_read_again() {
|
||||
fn the_read_after_a_script_that_left_the_folder_asks_for_a_frame() {
|
||||
let dir = folder("gone-frame");
|
||||
let mut app = app(&dir);
|
||||
// The reads' lanes wait until the test runs them, so the test knows when the read has ended.
|
||||
let jobs = Arc::new(ManualJobs::new());
|
||||
let held = crate::testing::ui_context();
|
||||
Host::builder(AppInfo { id: "vectorcraft", name: "VectorCraft", version: "0" }).jobs(jobs.clone()).install(&held);
|
||||
app.ui_ctx = Some(held.clone());
|
||||
let gone = write(&dir, "gone.js", DRAW);
|
||||
read(&app);
|
||||
scripts_menu::refresh(&app, &held);
|
||||
scripts_menu::finish();
|
||||
std::fs::remove_file(&gone).unwrap();
|
||||
let (tx, frames) = std::sync::mpsc::channel();
|
||||
let test = std::thread::current().id();
|
||||
// The observer sees every request; the repaint callback drops one no sooner than the first read's, still pending.
|
||||
ctx().set_repaint_observer(move |_| {
|
||||
held.set_repaint_observer(move |_| {
|
||||
// The read's lane asks from a thread of its own.
|
||||
if std::thread::current().id() != test {
|
||||
let _ = tx.send(());
|
||||
@@ -275,8 +280,10 @@ fn the_read_after_a_script_that_left_the_folder_asks_for_a_frame() {
|
||||
assert!(menus::run_ui_command(&mut app, scripts_menu::COMMAND, &json!({ "path": gone })).unwrap().is_err());
|
||||
// With the app's copy of the context dropped, only the queue's wake can still ask for a frame.
|
||||
app.ui_ctx = None;
|
||||
let asked = frames.recv_timeout(Duration::from_secs(10));
|
||||
ctx().set_repaint_observer(|_| {});
|
||||
let lanes = Arc::clone(&jobs);
|
||||
assert!(std::thread::spawn(move || lanes.run_all()).join().unwrap() > 0, "the read ran on a lane");
|
||||
let asked = frames.try_recv();
|
||||
held.set_repaint_observer(|_| {});
|
||||
assert_eq!(asked, Ok(()), "the finished read asks for a frame so an idle window takes it in");
|
||||
scripts_menu::finish();
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
|
||||
Reference in new issue
Block a user