mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
* Tests: UI tests wait for background work by time, not frame count (#4186) A frame count is not a time: on a busy runner the worker had not finished the open, or the page text had not arrived, within 30 frames or 50 hover rounds. support::step_until (#[must_use]) steps frames until a condition holds or 30 s pass, sleeping briefly between frames, and says whether it held; each test asserts on that with its own message. - control_open_replies_pending_while_the_worker_opens_and_focuses_once_it_has and mode_tabs_keep_the_hand_over_page_text_scrolled_under_them wait with it, and so does control.rs call() for its reply. - support::settle waits for every pending render and fails if the pages are not rendered within 30 s. It replaces all the render-pending settle loops (40 to 3000 frames) and the local settle/wait_for_pages wrappers, except text_select's double-click wait, which is held to 8 frames on purpose to stay inside egui's multi-click window, and view.rs's loops that already wait by a deadline. - wait_until is built on step_until, keeping its diagnostic message. - tabbing_back_to_the_same_field_then_saving_keeps_the_committed_value already waited 30 s for its file. It failed because its "same-frame" case shared its scratch directory with typing_and_saving_in_the_same_frame_saves_the_last_keystrokes, which runs in the same test process (sinceee1ee704, #1045) and deleted the directory mid-save. forms' and pickers' scratch() now give every call a directory of its own. Fixes #4186 * M14: update ctutils to 0.4.5 for RUSTSEC-2026-0385 The dependency-advisory gate rejects ctutils 0.4.2 (non-constant-time mask generation and u128 comparisons, fixed in 0.4.4). It comes in through crypto-bigint for the signing crates. Only its version and checksum change in Cargo.lock. (cherry picked from commit1f8811761a)
45 lines
1.7 KiB
Rust
45 lines
1.7 KiB
Rust
//! State-based waits for native preparation, which completes between UI frames.
|
|
use egui_kittest::Harness;
|
|
use pdfcraft_ui_egui::PdfCraftApp;
|
|
|
|
/// Step frames until `ready` holds or 30 seconds pass, and say whether it held. For background work
|
|
/// (a worker-thread open, page text arriving) that a test then asserts on itself: a frame count is
|
|
/// not a time, and a busy runner may not have finished the work within one. Sleeps briefly between
|
|
/// frames so the worker threads get the CPU.
|
|
#[must_use]
|
|
pub fn step_until(h: &mut Harness<'static, PdfCraftApp>, mut ready: impl FnMut(&mut Harness<'static, PdfCraftApp>) -> bool) -> bool {
|
|
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
|
|
loop {
|
|
h.step();
|
|
if ready(h) {
|
|
return true;
|
|
}
|
|
if std::time::Instant::now() >= deadline {
|
|
return false;
|
|
}
|
|
std::thread::sleep(std::time::Duration::from_millis(5));
|
|
}
|
|
}
|
|
|
|
/// Step frames until nothing is waiting to be rendered, and fail the test if that takes over 30
|
|
/// seconds: what a test checks next is on the rendered page.
|
|
pub fn settle(h: &mut Harness<'static, PdfCraftApp>) {
|
|
let settled = step_until(h, |h| {
|
|
h.run_steps(1);
|
|
!h.state().render_pending()
|
|
});
|
|
assert!(settled, "pages rendered");
|
|
}
|
|
|
|
pub fn wait_until(h: &mut Harness<'static, PdfCraftApp>, what: &str, ready: impl Fn(&PdfCraftApp) -> bool) {
|
|
let held = step_until(h, |h| ready(h.state()));
|
|
assert!(
|
|
held,
|
|
"timed out waiting for {what}: views={}, active={:?}, password={:?}, toast={:?}",
|
|
h.state().views.len(),
|
|
h.state().active,
|
|
h.state().password_prompt.as_ref().map(|p| (&p.name, &p.error)),
|
|
h.state().toast
|
|
);
|
|
}
|