Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+watch-summary-write-error.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write `--result` when `watch` cannot write the run summary, and exit 1.
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,7 @@ fn cmd_watch(w: &WatchArgs) -> Result<i32, Fail> {
),
}
}
let mut output_errors = Vec::new();
if let Err(f) = write_summary_with_pending_signal(
&s,
&mut res,
Expand All @@ -1662,10 +1663,18 @@ fn cmd_watch(w: &WatchArgs) -> Result<i32, Fail> {
Some(to_sorted(&doc)),
&[],
) {
return Err(signal_outranks(res.exit_code, f));
output_errors.push(f.msg);
}
if let Some(p) = w.result {
write_json(&to_sorted(&res), Some(p)).map_err(|f| signal_outranks(res.exit_code, f))?;
if let Err(f) = write_json(&to_sorted(&res), Some(p)) {
output_errors.push(f.msg);
}
}
if !output_errors.is_empty() {
return Err(signal_outranks(
res.exit_code,
Fail::new(exit::FAILED, output_errors.join("; ")),
));
}
Ok(res.exit_code)
}
Expand Down
32 changes: 32 additions & 0 deletions tests/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod common;

use common::*;
use serde_json::Value;
use std::os::unix::fs::PermissionsExt;
use std::process::{Command, Output, Stdio};
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -214,6 +215,37 @@ fn a_signal_while_watch_waits_for_the_summary_lock_preserves_signal_exit() {
assert_eq!(result["exit_code"], 143, "{result}");
}

#[test]
fn an_unwritable_run_summary_still_writes_the_result() {
let t = built("");
change(&t);
let run_dir = t.run_dir(LATER);
let log_dir = run_dir.join("cpu");
std::fs::create_dir_all(&log_dir).unwrap();
// The summary lock is a file this directory already holds. With the
// directory unwritable, the summary file is what cannot be created.
std::fs::write(run_dir.join(".summary.lock"), "").unwrap();
std::fs::set_permissions(&run_dir, std::fs::Permissions::from_mode(0o555)).unwrap();
let result = t.root().join("watch-result.json");
let result_arg = result.display().to_string();
let vars = eessi_vars(&t, "2023.06");
let output = watch(&t, LATER, &["--result", &result_arg], &with(&vars));
std::fs::set_permissions(&run_dir, std::fs::Permissions::from_mode(0o755)).unwrap();

let err = stderr(&output);
assert_eq!(code(&output), 1, "{err}");
assert!(err.contains("cannot write run summary:"), "{err}");
let summary = run_dir.join("summary.json");
assert!(err.contains(&summary.display().to_string()), "{err}");
assert!(!summary.exists());
let text =
std::fs::read_to_string(&result).unwrap_or_else(|error| panic!("{result:?}: {error}"));
let written: Value = serde_json::from_str(&text).unwrap();
assert_eq!(written["kind"], "result", "{written}");
assert_eq!(written["target"], "cpu", "{written}");
assert_eq!(written["exit_code"], 0, "{written}");
}

const LATER: &str = "20260102_000000";

const PLAN: &str = "\
Expand Down
Loading