From b328b7e96e1a0239b4357bf99ec00249173237b7 Mon Sep 17 00:00:00 2001 From: muraa-p <85794781+muraa-p@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:21:55 +0800 Subject: [PATCH] Wait for the cut the log-cap test is about (#1466) The test that a launched program's log is cut while it writes assumed the cut would come within the few seconds its stand-in spent printing, so on a loaded machine the file could end over its bound with nothing wrong. The stand-in now watches its own log and keeps printing until it has seen a cut and filled the file again, and the test checks it saw a cut before checking the size. No change outside the test. --- crates/platform/src/process.rs | 47 ++++++++++++++++++++++++---------- docs/ROADMAP.md | 4 +++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/crates/platform/src/process.rs b/crates/platform/src/process.rs index b4943190c..db5a769e5 100644 --- a/crates/platform/src/process.rs +++ b/crates/platform/src/process.rs @@ -1355,12 +1355,13 @@ mod launch_tests { assert!(text.contains("out-line") && text.contains("err-line"), "{text}"); } - /// A program that prints far more than the cap keeps running to the end, and its log stays - /// small: the cut is ours, not something its own writes run into. + /// A program that prints far more than the cap keeps running to the end, and its log is cut + /// while it writes: the cut is ours, not something its own writes run into. #[test] fn a_launched_programs_log_is_cut_back_while_it_runs() { let dir = tempfile::tempdir().unwrap(); let log = dir.path().join("run.log"); + std::fs::write(dir.path().join("log-path"), log.display().to_string()).unwrap(); std::fs::write(dir.path().join("log-writer"), b"go").unwrap(); let l = Launch::new(std::env::current_exe().unwrap()) .args(["--ignored", "--exact", "process::launch_tests::log_writer_stand_in"]) @@ -1371,16 +1372,23 @@ mod launch_tests { .unwrap(); let ended = l.wait_timeout(Duration::from_secs(120)).expect("the writer ended"); assert_eq!(ended.code, Some(0), "a cut never breaks the program's own writes"); - let wrote: u64 = std::fs::read_to_string(dir.path().join("wrote")).unwrap().trim().parse().unwrap(); - assert!(wrote > 4 * LOG_CAP, "the stand-in printed more than the cap: {wrote}"); + let report = std::fs::read_to_string(dir.path().join("wrote")).unwrap(); + let (wrote, cuts): (u64, u32) = { + let mut parts = report.split_whitespace(); + (parts.next().unwrap().parse().unwrap(), parts.next().unwrap().parse().unwrap()) + }; + assert!(wrote > LOG_CAP, "the stand-in printed more than the cap: {wrote}"); + // The stand-in waits for a cut and writes on past it, so this doesn't depend on how fast + // the cuts come: it printed more than the cap, saw the file shrink, and its later writes + // were accepted. + assert!(cuts >= 1, "the log was cut while the program ran: {report}"); let kept = std::fs::metadata(&log).unwrap().len(); - // A cut comes every couple of seconds, so the file can grow past the cap between cuts; what - // it can't do is keep everything the program printed. - assert!(kept <= 4 * LOG_CAP, "the log stayed under a few caps after {wrote} bytes: {kept}"); + assert!(kept <= 2 * LOG_CAP, "the log stayed small after {wrote} bytes: {kept}"); } - /// Prints 8 MiB in chunks over about four seconds, enough for several cuts, and says how much - /// it printed. Only runs when the test above leaves its guard file in the working directory. + /// Prints past the cap in chunks, waits to see its own log shrink, writes on to show the cut + /// left its writes alone, then says how much it printed and how many cuts it saw. Only runs + /// when the test above leaves its guard files in the working directory. #[test] #[ignore = "stand-in invoked by a_launched_programs_log_is_cut_back_while_it_runs"] fn log_writer_stand_in() { @@ -1388,17 +1396,30 @@ mod launch_tests { if std::fs::read("log-writer").is_err() { return; } + let log = std::fs::read_to_string("log-path").unwrap().trim().to_string(); let chunk = vec![b'x'; 64 * 1024]; let mut out = std::io::stdout(); - let mut wrote = 0u64; - for _ in 0..128 { + let (mut wrote, mut cuts, mut last) = (0u64, 0u32, 0u64); + // Enough chunks for a loaded machine: a cut comes every couple of seconds, and this goes on + // until it has seen one and written past it. + for _ in 0..4096 { out.write_all(&chunk).unwrap(); out.write_all(b"\n").unwrap(); out.flush().unwrap(); wrote += chunk.len() as u64 + 1; - std::thread::sleep(Duration::from_millis(30)); + let kept = std::fs::metadata(&log).map(|m| m.len()).unwrap_or(0); + if kept < last { + cuts += 1; + } + last = kept; + // A cut has been seen and the writes after it have filled the file again, which is the + // thing worth proving: the cut doesn't get in the program's way. + if cuts > 0 && kept > LOG_CAP / 2 { + break; + } + std::thread::sleep(Duration::from_millis(20)); } - std::fs::write("wrote", wrote.to_string()).unwrap(); + std::fs::write("wrote", format!("{wrote} {cuts}")).unwrap(); } #[test] diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index c7eee39bc..81d921520 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -1379,6 +1379,10 @@ to the project next. that file back to empty once it passes 1 MiB, so its writes never fail or block and a program that outlives us is untouched; past our exit the file grows again, as it did before. — claimed: muraa-p, branch bugfix/r2.10-cap-run-log +- [x] The log-cap test assumed a cut lands within a few seconds of the stand-in's printing, so a + loaded machine could grow the file past the bound with nothing wrong. The stand-in now reads + its own log and stops once it has seen a cut and written past it + — claimed: muraa-p, branch test/r2.10-log-cap-waits-for-cut - [ ] Opening a pin that's already running brings its window to the front, instead of a message - [x] How much space pins take in Settings — claimed: Afloat16, branch feature/r2.10-pinned-copy-storage