Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

tests: the pending-open control test waits for the worker by time, not by 30 frames

Guillem Hermidabf81191122fd
diff --git a/crates/ui-egui/tests/it/control.rs b/crates/ui-egui/tests/it/control.rs
index 54bfe2fa3..aa71d411b 100644
--- a/crates/ui-egui/tests/it/control.rs
+++ b/crates/ui-egui/tests/it/control.rs
@@ -1672,15 +1672,19 @@ fn control_open_replies_pending_while_the_worker_opens_and_focuses_once_it_has()
assert_eq!(first["pending"], true, "{first}");
// The worker completes the open on later frames; the tab shows, and only then does a
- // repeated open focus it instead of reporting another pending open.
+ // repeated open focus it instead of reporting another pending open. The worker is a thread
+ // of its own, so the wait is bounded by time: a busy runner can draw 30 frames before it has
+ // read the file.
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
let mut documents = 0;
- for _ in 0..30 {
+ while std::time::Instant::now() < deadline {
h.run_steps(1);
let state = ok(&mut h, &c, "ui.state", json!({}));
documents = state["documents"].as_array().map(|d| d.len()).unwrap_or_default();
if documents == 1 {
break;
}
+ std::thread::sleep(std::time::Duration::from_millis(5));
}
assert_eq!(documents, 1, "the pending open completed into a tab");