mirror of
https://github.com/storytold/figcraft.git
synced 2026-12-05 19:51:38 -05:00
* M12: restore test waits for a crashed run's folder lock to free before recovering (#3015) * M12: restore test also waits before the quit run takes the crashed run's folder back (#3015)
This commit is contained in:
@@ -439,6 +439,19 @@ pub fn recover(root: &Path, s: &mut Session) -> usize {
|
||||
recover_all(root, s).copies
|
||||
}
|
||||
|
||||
/// Test hook: wait, up to a deadline, until no folder under `root` looks held. Another test's
|
||||
/// child between its `fork` and its `exec` can hold an ended run's lock for longer than
|
||||
/// `LOCK_WAIT` on a loaded machine (#3015).
|
||||
#[cfg(test)]
|
||||
pub fn wait_for_ended_runs(root: &Path) {
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
|
||||
let held =
|
||||
|| std::fs::read_dir(root).into_iter().flatten().flatten().any(|e| matches!(lock_folder(&e.path()), Err(std::fs::TryLockError::WouldBlock)));
|
||||
while held() && std::time::Instant::now() < deadline {
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
|
||||
/// Open the copies left by runs that ended without closing (folders under `root` whose lock is
|
||||
/// free, and copies directly in `root` from older versions) as unsaved documents. Each is kept
|
||||
/// until this run has its own copy of the document ([`Recovered::waiting`]); a copy of one of your
|
||||
|
||||
@@ -12,7 +12,7 @@ use figcraft_engine::Session;
|
||||
use figcraft_ui_egui::FigApp;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::recovery::{Recovery, recover};
|
||||
use crate::recovery::{Recovery, recover, wait_for_ended_runs};
|
||||
use crate::services::{Desktop, Start, mark_restoring, start_session};
|
||||
|
||||
fn root(name: &str) -> PathBuf {
|
||||
@@ -205,6 +205,7 @@ fn after_a_crash_unsaved_documents_come_back_beside_the_restored_tabs_and_a_quit
|
||||
r.write(&s, true);
|
||||
// Killed: the lock goes with the process. The next start gets both back, and the tab.
|
||||
drop(r);
|
||||
wait_for_ended_runs(&recovery);
|
||||
let mut killed = next(&dir);
|
||||
assert_eq!(recover(&recovery, &mut killed), 2);
|
||||
assert_eq!(start_session(Some(&dir), &mut killed, false), Start::Restore);
|
||||
@@ -212,7 +213,9 @@ fn after_a_crash_unsaved_documents_come_back_beside_the_restored_tabs_and_a_quit
|
||||
assert_eq!(killed.docs.iter().filter(|d| d.path.as_deref() == Some(paths[0].as_str()) && !d.is_dirty()).count(), 1, "the tab, as saved");
|
||||
mark_restoring(&dir, false);
|
||||
// A normal quit instead (Don't save was the answer, or there was nothing to ask): the
|
||||
// copies go, and the saved file is all that comes back.
|
||||
// copies go, and the saved file is all that comes back. (This run takes back the folder the
|
||||
// recover above let go of, once it is free.)
|
||||
wait_for_ended_runs(&recovery);
|
||||
let mut r = Recovery::start(&recovery).unwrap();
|
||||
r.write(&s, true);
|
||||
r.finish();
|
||||
|
||||
Reference in New Issue
Block a user