crates/monetize-server/src/estate_order/tests/lay_journal_aside.rs
//! **A28 M16: a failed lay's journal that cannot be kept beside is never silently left.** A
//! paid order that fails is set up again from nothing, and its lay journal starts over: the
//! failed one is renamed `journal.failed-<n>`. A rename that failed was dropped (`let _ =`),
//! so the next lay read the failed lay's records as its own. Now the journal is removed when
//! it cannot be kept, and the run's history says so.
use super::*;
/// ★ The kept name is taken (a directory with something in it), so the rename fails: the
/// failed lay's journal is removed instead, the history says why, and the retried lay starts
/// with a journal of its own.
#[test]
fn a_failed_lays_journal_that_cannot_be_kept_beside_is_removed_and_said() {
let r = rig_with("journal-aside", cfg(), "FAIL");
start_for(
&r.state,
"acme",
"buyer@example.com",
"",
"alice",
&EstateSizes::default(),
)
.unwrap();
let dir = r.state.estates.run_dir("acme").expect("a run directory");
std::fs::create_dir_all(dir.join("journal.failed-1")).unwrap();
std::fs::write(
dir.join("journal.failed-1").join("taken"),
b"the name is taken",
)
.unwrap();
r.pay.authorize(&handle_of(&r, "acme"));
drive(&r.state, "acme");
let run = r.state.estates.get("acme").unwrap();
assert_eq!(run.failures, 2, "{:#?}", run.history);
let said: Vec<&str> = run
.history
.iter()
.map(|t| t.note.as_str())
.filter(|n| n.contains("could not be kept beside"))
.collect();
assert_eq!(
said.len(),
1,
"the first failure says its journal was not kept: {:#?}",
run.history
);
assert!(said[0].contains("removed"), "{said:?}");
assert!(
dir.join("journal.failed-2").is_file(),
"the second failure's journal is kept beside as before"
);
}