mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-02 20:19:40 -05:00
Exercise the native quit timeout warning with a held render
This commit is contained in:
1 parent
3c3010864d
commit
1a95adbc19
2 files changed
+64
-3
No files matched your search
@@ -229,9 +229,7 @@ impl eframe::App for App {
|
||||
log::error!("saving the library failed: {e}");
|
||||
}
|
||||
// last, with everything saved: no render may be inside the GPU driver when the process ends
|
||||
if !self.0.shutdown(EXIT_WAIT) {
|
||||
log::warn!("quit: background work was still running past the exit wait ({EXIT_WAIT:?}; longer for a GPU device start-up)");
|
||||
}
|
||||
stop_background_work_at_exit(&mut self.0, EXIT_WAIT);
|
||||
// macOS only: the process ends below without running destructors, and only the lock's
|
||||
// `Drop` removes `catalog.lock.owner` (the OS frees the lock, not the note), so let go of
|
||||
// the library's lock here, saved or not (we leave either way). Elsewhere eframe drops the
|
||||
@@ -262,6 +260,12 @@ impl eframe::App for App {
|
||||
/// a second; anything slower gives way to quitting.
|
||||
const EXIT_WAIT: std::time::Duration = std::time::Duration::from_secs(2);
|
||||
|
||||
fn stop_background_work_at_exit(app: &mut LightcraftApp, render_wait: std::time::Duration) {
|
||||
if !app.shutdown(render_wait) {
|
||||
log::warn!("quit: background work was still running past the exit wait ({render_wait:?}; longer for a GPU device start-up)");
|
||||
}
|
||||
}
|
||||
|
||||
/// Import files passed on the command line once the library is open. Preserve an explicit Detail
|
||||
/// startup view; Grid and Last keep the existing Photo Grid launch behavior.
|
||||
fn start_launch_files(app: &mut LightcraftApp, files: Vec<String>) {
|
||||
|
||||
@@ -916,3 +916,60 @@ fn quitting_waits_for_a_warm_up_past_the_exit_wait() {
|
||||
assert!(out.status.success(), "{:?}\n{stdout}{}", out.status, String::from_utf8_lossy(&out.stderr));
|
||||
assert!(stdout.contains("quit after the warm-up"), "the child didn't run the test: {stdout}");
|
||||
}
|
||||
|
||||
/// The host reports an ordinary render still running at its deadline, but an idle shutdown is quiet.
|
||||
#[test]
|
||||
fn quit_warns_when_an_ordinary_render_outlasts_the_deadline() {
|
||||
use lightcraft_engine::media::SourceRef;
|
||||
use lightcraft_ui_egui::render::Slot;
|
||||
use std::sync::{Arc, Mutex, mpsc};
|
||||
use std::time::Duration;
|
||||
|
||||
const TEST: &str = "tests::quit_warns_when_an_ordinary_render_outlasts_the_deadline";
|
||||
const CHILD: &str = "LIGHTCRAFT_TEST_QUIT_RENDER_TIMEOUT";
|
||||
if std::env::var_os(CHILD).is_some() {
|
||||
// The app shutdown gate and logger are process-global. No driver is used: a real
|
||||
// render-pool worker waits in its source loader and is released before this child returns.
|
||||
logging::install().expect("logger in a fresh test child").no_file();
|
||||
let mut session = Session::with_demo();
|
||||
let id = session.visible_cloned()[0];
|
||||
let mut job = session.render_job(id, 32, 32, false, false).unwrap();
|
||||
let mut app = LightcraftApp::new(session, Services::default());
|
||||
let (entered_tx, entered_rx) = mpsc::channel();
|
||||
let (release_tx, release_rx) = mpsc::channel::<()>();
|
||||
let release_rx = Mutex::new(release_rx);
|
||||
job.source = SourceRef::File {
|
||||
path: "held-render-fixture".into(),
|
||||
max_edge: 32,
|
||||
loader: Some(Arc::new(move |_, _, _| {
|
||||
entered_tx.send(()).unwrap();
|
||||
// The sender also drops during unwinding, so a failed assertion won't strand the worker.
|
||||
let _ = release_rx.lock().unwrap().recv();
|
||||
Err("fixture render released".into())
|
||||
})),
|
||||
fallback: None,
|
||||
denoise: None,
|
||||
camera_profile: None,
|
||||
outliers: false,
|
||||
reduced: None,
|
||||
};
|
||||
app.renderer.request(Slot::Main, job, 1);
|
||||
entered_rx.recv_timeout(Duration::from_secs(30)).expect("the real render worker entered its loader");
|
||||
stop_background_work_at_exit(&mut app, Duration::ZERO);
|
||||
drop(release_tx);
|
||||
assert!(app.renderer.shutdown(Duration::from_secs(30)), "released render drained");
|
||||
stop_background_work_at_exit(&mut app, Duration::ZERO);
|
||||
return;
|
||||
}
|
||||
let out = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args(["--exact", TEST, "--nocapture"])
|
||||
.env(CHILD, "1")
|
||||
.env("LIGHTCRAFT_GPU", "0")
|
||||
.env("LIGHTCRAFT_NO_PREFS", "1")
|
||||
.env("LIGHTCRAFT_LOG", "warn")
|
||||
.output()
|
||||
.unwrap();
|
||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||
assert!(out.status.success(), "{}\n{stderr}", String::from_utf8_lossy(&out.stdout));
|
||||
assert_eq!(stderr.matches("quit: background work was still running past the exit wait").count(), 1, "{stderr}");
|
||||
}
|
||||
Reference in new issue
Block a user