Tests: a file placed while idle renders on the test thread

a_file_placed_while_idle_follows_its_changes asserts that an idle
document without links asks for no frame. Its app started the real render
worker, and once a frame took over 8 ms the canvas sent the next render to
it. The worker asks for a repaint when it finishes, at a time the test
does not control, so under heavy CPU load the asserted frame could report
a repaint delay of 0 instead of none.

The test now sets canvas.worker_started, as the cursor idle test does, so
every frame renders on the test thread. It also dates the rewritten file
2 s after the original with File::set_times, as the opening tests do,
instead of sleeping 30 ms before the write. Shipped code is unchanged.
This commit is contained in:
dotCooCoo
2026-11-04 22:29:35 +07:00
committed by bflatastic
parent 609528220b
commit 9b8561b225
+7 -1
View File
@@ -786,6 +786,9 @@ fn idle(app: &mut VectorcraftApp, ctx: &egui::Context, time: &mut f64, secs: f64
#[test]
fn a_file_placed_while_idle_follows_its_changes() {
let mut app = app();
// Every frame renders on this thread, however long it takes: a frame finished by the render
// worker during the idle frames asks for a repaint.
app.canvas.worker_started = true;
app.run("prefs.set", json!({"key": "updateLinks", "value": "automatically"})).unwrap();
let ctx = egui::Context::default();
let mut time = 0.0;
@@ -799,9 +802,12 @@ fn a_file_placed_while_idle_follows_its_changes() {
app.run("file.place", json!({"path": path})).unwrap();
let id = app.session.active().unwrap().selection.objects[0];
idle(&mut app, &ctx, &mut time, 3.0, &|_| false);
std::thread::sleep(std::time::Duration::from_millis(30));
let stamp = std::fs::metadata(&path).unwrap().modified().unwrap();
let changed = png(60, 30, 72.0);
std::fs::write(&path, &changed).unwrap();
// The rewritten file is dated 2 s later, however fast it was written.
let later = std::fs::FileTimes::new().set_modified(stamp + std::time::Duration::from_secs(2));
std::fs::OpenOptions::new().write(true).open(&path).unwrap().set_times(later).unwrap();
let hash = vectorcraft_doc::links::hash_bytes(&changed);
let updated = |app: &VectorcraftApp| {
let st = app.session.active().unwrap();