From 6069e74df0d3d8e4fdfc5a6c817657183218f4f3 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 12:25:24 +0000 Subject: [PATCH 1/6] test: drop three checks already made elsewhere The shared stdout sweep already runs `eb-junit --result`, `--help`, and `--version`. The ReFrame command-line test already feeds `gromacs+gpu(v2)`. The JUnit golden file already has `tests="0"` and no `testcase`. Rust tests: 800 to 797. --- src/bin/eb-junit.rs | 13 ------------- src/bin/eb-test-map.rs | 8 -------- tests/junit.rs | 22 ---------------------- 3 files changed, 43 deletions(-) diff --git a/src/bin/eb-junit.rs b/src/bin/eb-junit.rs index 9a37d827..55fd1e24 100644 --- a/src/bin/eb-junit.rs +++ b/src/bin/eb-junit.rs @@ -888,19 +888,6 @@ mod tests { assert!(xml.contains("logs/later.log")); } - #[test] - fn an_empty_successful_run_has_no_cases() { - let text = r#"{ - "schema_version": 1, "kind": "result", "site": "example", "target": "cpu", - "build_type": "production", "run_id": "n", "exit_code": 0, "lines": [] - }"#; - let xml = render(text).unwrap(); - assert!( - xml.contains("tests=\"0\" failures=\"0\" errors=\"0\" skipped=\"0\" time=\"0.000\"") - ); - assert!(!xml.contains(" Date: Thu, 26 Nov 2026 12:30:15 +0000 Subject: [PATCH 2/6] test: fold near-copy cases into one table each Eleven groups of near-copy tests become one table each. Every old case stays as a row: ReFrame escapes, duration bounds, illegal `--stack-checks` mixes, `eb-cvmfs` process groups, `sbom` bodies, truncated audit documents, EasyStack options, resume skips, closed stdout (`EPIPE`), dry-run lines, and malformed input. Those rows check the producer, the path, and `invalid JSON`. Rust tests: 797 to 772. --- src/bin/eb-retry-list.rs | 59 ++++---- src/resume.rs | 10 +- tests/attest.rs | 43 ------ tests/audit.rs | 216 ++++++++++++++---------------- tests/cvmfs.rs | 267 +++++++++++++++---------------------- tests/gap.rs | 37 +---- tests/junit.rs | 212 +++++++++++++++++++++++------ tests/metrics.rs | 22 --- tests/package_plan.rs | 18 --- tests/retry_list.rs | 33 ----- tests/sbom.rs | 46 +++---- tests/shard_weights.rs | 135 ++++--------------- tests/stack_checks.rs | 118 ++++++---------- tests/standalone_output.rs | 247 ++++++++++++++++++++++++++++++++-- tests/test_map.rs | 128 +++++------------- 15 files changed, 753 insertions(+), 838 deletions(-) diff --git a/src/bin/eb-retry-list.rs b/src/bin/eb-retry-list.rs index 81a50ef1..d0569769 100644 --- a/src/bin/eb-retry-list.rs +++ b/src/bin/eb-retry-list.rs @@ -1028,40 +1028,31 @@ oom=2 fits=1 builds=3 nodes=1 #[test] fn generated_easystacks_keep_short_easybuild_options() { - let entry = easystack_entry("Big-1.0.eb", &["-f".into()]).unwrap(); - let document = serde_yaml::Value::Mapping(serde_yaml::Mapping::from_iter([( - serde_yaml::Value::String("easyconfigs".into()), - serde_yaml::Value::Sequence(vec![entry]), - )])); - let text = serde_yaml::to_string(&document).unwrap(); - let lines = easystack::parse(&text).unwrap(); - assert_eq!(lines[0].args, ["-f"]); - } - - #[test] - fn generated_easystacks_keep_repeated_amend_options() { - let entry = easystack_entry( - "Big-1.0.eb", - &[ - "--try-amend=versionsuffix=-a".into(), - "--try-amend".into(), - "toolchain=foss,2025a".into(), - ], - ) - .unwrap(); - let document = serde_yaml::Value::Mapping(serde_yaml::Mapping::from_iter([( - serde_yaml::Value::String("easyconfigs".into()), - serde_yaml::Value::Sequence(vec![entry]), - )])); - let text = serde_yaml::to_string(&document).unwrap(); - let lines = easystack::parse(&text).unwrap(); - assert_eq!( - lines[0].args, - [ - "--try-amend=versionsuffix=-a", - "--try-amend=toolchain=foss,2025a" - ] - ); + let rows: &[(&[&str], &[&str])] = &[ + (&["-f"], &["-f"]), + ( + &[ + "--try-amend=versionsuffix=-a", + "--try-amend", + "toolchain=foss,2025a", + ], + &[ + "--try-amend=versionsuffix=-a", + "--try-amend=toolchain=foss,2025a", + ], + ), + ]; + for (input, want) in rows { + let owned: Vec = input.iter().map(|arg| (*arg).to_string()).collect(); + let entry = easystack_entry("Big-1.0.eb", &owned).unwrap(); + let document = serde_yaml::Value::Mapping(serde_yaml::Mapping::from_iter([( + serde_yaml::Value::String("easyconfigs".into()), + serde_yaml::Value::Sequence(vec![entry]), + )])); + let text = serde_yaml::to_string(&document).unwrap(); + let lines = easystack::parse(&text).unwrap(); + assert_eq!(lines[0].args, *want); + } } #[test] diff --git a/src/resume.rs b/src/resume.rs index 55933a20..9607c79b 100644 --- a/src/resume.rs +++ b/src/resume.rs @@ -394,6 +394,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let output = dir.path().join("mod.lua"); std::fs::write(&output, "module\n").unwrap(); + let kept = output.display().to_string(); let prior = Prior { digest: "aa".into(), lines: vec![ @@ -405,7 +406,7 @@ mod tests { PriorLine { easyconfig: "Foo-1.0.eb".into(), status: "success".into(), - outputs: vec![output.display().to_string()], + outputs: vec![kept], }, ], }; @@ -416,11 +417,7 @@ mod tests { &prior, ); assert!(skip.is_empty(), "{skip:?}"); - } - #[test] - fn a_successful_shard_is_skipped_when_its_outputs_remain() { - let dir = tempfile::tempdir().unwrap(); let foo = dir.path().join("foo.lua"); std::fs::write(&foo, "module\n").unwrap(); let prior = Prior { @@ -445,10 +442,7 @@ mod tests { &prior, ); assert_eq!(skip.into_iter().collect::>(), ["shard-01"]); - } - #[test] - fn a_missing_output_is_not_skipped() { let prior = Prior { digest: "aa".into(), lines: vec![PriorLine { diff --git a/tests/attest.rs b/tests/attest.rs index 8c5e9b72..e47018b6 100644 --- a/tests/attest.rs +++ b/tests/attest.rs @@ -660,49 +660,6 @@ fn the_list_variable_does_not_conflict_with_the_recorded_list() { assert_eq!(typed.status.code(), Some(2)); } -#[test] -fn malformed_verify_input_names_the_producer_and_path() { - let tree = Tree::new(); - let root = tree.path(); - let mut site = bare_site(root); - site.push_str(&format!( - "\n[attest]\nenabled = true\nlog_dir = \"{r}/log\"\nkey = \"{r}/key.pem\"\norigin = \"example.org/inputs\"\ntrusted = [\"example.org/inputs+abcd+AAAA\"]\neasyconfigs = [\"{r}/easyconfigs\"]\n", - r = root.display() - )); - std::fs::create_dir_all(root.join("easyconfigs")).unwrap(); - std::fs::write(root.join("key.pem"), "k\n").unwrap(); - std::fs::write(root.join("site.toml"), site).unwrap(); - std::fs::write(root.join("list.txt"), "Foo-1.0.eb\n").unwrap(); - let from = root.join("plan.json"); - std::fs::write(&from, "{").unwrap(); - - let output = tree.run( - &[ - "verify", - "--site", - root.join("site.toml").to_str().unwrap(), - "--list", - root.join("list.txt").to_str().unwrap(), - "--target", - "cpu", - "--build-type", - "production", - "--from", - from.to_str().unwrap(), - ], - &[], - ); - - assert_eq!(output.status.code(), Some(2)); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - format!( - "ERROR [main] -: eb-pipeline plan wrote invalid JSON to {}: EOF while parsing an object at line 1 column 1\n", - from.display() - ) - ); -} - #[test] fn a_stale_record_temporary_does_not_block_attestation() { let tree = Tree::new(); diff --git a/tests/audit.rs b/tests/audit.rs index 7f9b9c37..1f7a23a8 100644 --- a/tests/audit.rs +++ b/tests/audit.rs @@ -187,123 +187,107 @@ fn cve_mode_runs_stack_sbom_and_component_reach() { #[test] fn audit_refuses_truncated_rebuild_set_json() { - let t = setup(""); - write_exec(&t.stubs.join("eb-stack"), EB_STACK_AUDIT); - t.eessi_module("Foo", "1.0-GCCcore-13.2.0"); - let findings = t.root().join("findings.csv"); - std::fs::write( - &findings, - "severity,vuln_id,package,used_in\nhigh,CVE-2026-0001,zlib,Foo/1.0-GCCcore-13.2.0\n", - ) - .unwrap(); - let out_dir = t.root().join("audit"); - let mut vars: Vec<(&str, &str)> = eessi_vars(&t, "2026.06") - .into_iter() - .map(|(key, value)| (key, Box::leak(value.into_boxed_str()) as &str)) - .collect(); - vars.push(("STUB_AUDIT_TRUNCATED_REBUILD_SET", "1")); - - let output = eb_pipeline( - &t, - &[ - "audit", - "--site", - &t.site.display().to_string(), - "--target", - "cpu", - "--findings", - &findings.display().to_string(), - "--out-dir", - &out_dir.display().to_string(), - ], - &vars, - ); - - assert_eq!(code(&output), 1, "{}", stderr(&output)); - assert!( - stderr(&output).contains("rebuild-set.json") - && stderr(&output).contains("wrote invalid JSON"), - "{}", - stderr(&output) - ); - assert!(!out_dir.join("rebuilds").exists()); -} - -#[test] -fn audit_refuses_truncated_sbom_json() { - let t = setup("[sbom]\nenabled = true\nlock = \"@ROOT@/stack.lock.json\""); - write_exec(&t.stubs.join("eb-stack"), EB_STACK_AUDIT); - t.eessi_module("Foo", "1.0-GCCcore-13.2.0"); - std::fs::write(t.root().join("stack.lock.json"), "{\"packages\":[]}").unwrap(); - let out_dir = t.root().join("audit"); - let mut vars: Vec<(&str, &str)> = eessi_vars(&t, "2026.06") - .into_iter() - .map(|(key, value)| (key, Box::leak(value.into_boxed_str()) as &str)) - .collect(); - vars.push(("STUB_AUDIT_TRUNCATED_SBOM", "1")); - - let output = eb_pipeline( - &t, - &[ - "audit", - "--site", - &t.site.display().to_string(), - "--target", - "cpu", - "--cve", - "CVE-2026-0001", - "--out-dir", - &out_dir.display().to_string(), - ], - &vars, - ); - - assert_eq!(code(&output), 1, "{}", stderr(&output)); - assert!( - stderr(&output).contains("stack.cdx.json") - && stderr(&output).contains("wrote invalid JSON"), - "{}", - stderr(&output) - ); - assert!(!t.calls("ebstack").contains("component-reach")); -} - -#[test] -fn audit_refuses_truncated_component_json() { - let t = setup("[sbom]\nenabled = true\nlock = \"@ROOT@/stack.lock.json\""); - write_exec(&t.stubs.join("eb-stack"), EB_STACK_AUDIT); - t.eessi_module("Foo", "1.0-GCCcore-13.2.0"); - std::fs::write(t.root().join("stack.lock.json"), "{\"packages\":[]}").unwrap(); - let out_dir = t.root().join("audit"); - let mut vars: Vec<(&str, &str)> = eessi_vars(&t, "2026.06") - .into_iter() - .map(|(key, value)| (key, Box::leak(value.into_boxed_str()) as &str)) - .collect(); - vars.push(("STUB_AUDIT_TRUNCATED_COMPONENT", "1")); - - let output = eb_pipeline( - &t, - &[ - "audit", - "--site", - &t.site.display().to_string(), - "--target", - "cpu", - "--cve", - "CVE-2026-0001", - "--out-dir", - &out_dir.display().to_string(), - ], - &vars, - ); + struct Row { + site: &'static str, + env_flag: &'static str, + findings: bool, + lock: bool, + needle: &'static str, + no_component_reach: bool, + no_rebuilds: bool, + } + let rows = [ + Row { + site: "", + env_flag: "STUB_AUDIT_TRUNCATED_REBUILD_SET", + findings: true, + lock: false, + needle: "rebuild-set.json", + no_component_reach: false, + no_rebuilds: true, + }, + Row { + site: "[sbom]\nenabled = true\nlock = \"@ROOT@/stack.lock.json\"", + env_flag: "STUB_AUDIT_TRUNCATED_SBOM", + findings: false, + lock: true, + needle: "stack.cdx.json", + no_component_reach: true, + no_rebuilds: false, + }, + Row { + site: "[sbom]\nenabled = true\nlock = \"@ROOT@/stack.lock.json\"", + env_flag: "STUB_AUDIT_TRUNCATED_COMPONENT", + findings: false, + lock: true, + needle: "component-reach.json", + no_component_reach: false, + no_rebuilds: false, + }, + ]; + for row in rows { + let t = setup(row.site); + write_exec(&t.stubs.join("eb-stack"), EB_STACK_AUDIT); + t.eessi_module("Foo", "1.0-GCCcore-13.2.0"); + let findings = t.root().join("findings.csv"); + if row.findings { + std::fs::write( + &findings, + "severity,vuln_id,package,used_in\nhigh,CVE-2026-0001,zlib,Foo/1.0-GCCcore-13.2.0\n", + ) + .unwrap(); + } + if row.lock { + std::fs::write(t.root().join("stack.lock.json"), "{\"packages\":[]}").unwrap(); + } + let out_dir = t.root().join("audit"); + let owned = eessi_vars(&t, "2026.06"); + let mut vars: Vec<(&str, &str)> = owned + .iter() + .map(|(key, value)| (*key, value.as_str())) + .collect(); + vars.push((row.env_flag, "1")); + let site_path = t.site.display().to_string(); + let out = out_dir.display().to_string(); + let findings_path = findings.display().to_string(); + let mut args = vec![ + "audit".to_string(), + "--site".into(), + site_path, + "--target".into(), + "cpu".into(), + ]; + if row.findings { + args.push("--findings".into()); + args.push(findings_path); + } else { + args.push("--cve".into()); + args.push("CVE-2026-0001".into()); + } + args.push("--out-dir".into()); + args.push(out); + let refs: Vec<&str> = args.iter().map(String::as_str).collect(); + let output = eb_pipeline(&t, &refs, &vars); - assert_eq!(code(&output), 1, "{}", stderr(&output)); - assert!( - stderr(&output).contains("component-reach.json") - && stderr(&output).contains("wrote invalid JSON"), - "{}", - stderr(&output) - ); + assert_eq!(code(&output), 1, "{} {}", row.needle, stderr(&output)); + assert!( + stderr(&output).contains(row.needle) && stderr(&output).contains("wrote invalid JSON"), + "{} {}", + row.needle, + stderr(&output) + ); + if row.no_rebuilds { + assert!(!out_dir.join("rebuilds").exists(), "{}", row.needle); + } + if row.no_component_reach { + assert!( + !t.calls("ebstack").contains("component-reach"), + "{} {}", + row.needle, + t.calls("ebstack") + ); + } + } } #[test] diff --git a/tests/cvmfs.rs b/tests/cvmfs.rs index 01766903..c90bfc5c 100644 --- a/tests/cvmfs.rs +++ b/tests/cvmfs.rs @@ -169,64 +169,50 @@ fn successful_sync_opens_and_publishes_one_transaction() { #[test] fn sync_without_a_timeout_stays_in_the_callers_process_group() { - let fixture = Fixture::new(); - let group = fixture.dir.path().join("group"); - write_exec( - &fixture.sync, - "#!/bin/sh\n\ - echo \"sync $*\" >> \"$CALLS\"\n\ - set -- $(/bin/cat /proc/$$/stat)\n\ - echo \"$$ ${5}\" > \"$GROUP\"\n", - ); - let output = fixture.command().env("GROUP", &group).output().unwrap(); - assert_eq!(code(&output), 0, "{}", stderr(&output)); - let identity = std::fs::read_to_string(group).unwrap(); - let (pid, process_group) = identity.trim().split_once(' ').unwrap(); - assert_ne!(pid, process_group); - assert_eq!(process_group, current_process_group()); - assert_eq!(output.stdout, b""); - assert_eq!(output.stderr, b""); -} - -#[test] -fn publish_without_a_timeout_stays_in_the_callers_process_group() { - let fixture = Fixture::new(); - let group = fixture.dir.path().join("publish-group"); - let output = fixture - .command() - .env("STUB_PUBLISH_GROUP", &group) - .output() - .unwrap(); - assert_eq!(code(&output), 0, "{}", stderr(&output)); - let identity = std::fs::read_to_string(group).unwrap(); - let (pid, process_group) = identity.trim().split_once(' ').unwrap(); - assert_ne!(pid, process_group); - assert_eq!(process_group, current_process_group()); - assert_eq!(output.stdout, b""); - assert_eq!(output.stderr, b""); - assert_eq!(fixture.calls().as_bytes(), HISTORICAL_CALLS); -} - -#[test] -fn check_without_a_timeout_stays_in_the_callers_process_group() { - let fixture = Fixture::new(); - let group = fixture.dir.path().join("check-group"); - let output = fixture - .command_with_options(None, None, None, &["--check"]) - .env("STUB_CHECK_GROUP", &group) - .output() - .unwrap(); - assert_eq!(code(&output), 0, "{}", stderr(&output)); - let identity = std::fs::read_to_string(group).unwrap(); - let (pid, process_group) = identity.trim().split_once(' ').unwrap(); - assert_ne!(pid, process_group); - assert_eq!(process_group, current_process_group()); - assert_eq!(output.stdout, b""); - assert_eq!(output.stderr, b""); - assert_eq!( - fixture.calls().as_bytes(), - b"list\ntransaction repo.example\nsync --delete\npublish repo.example\ncheck repo.example\n" - ); + for phase in ["sync", "publish", "check"] { + let fixture = Fixture::new(); + let group = fixture.dir.path().join("group"); + let output = match phase { + "sync" => { + write_exec( + &fixture.sync, + "#!/bin/sh\n\ + echo \"sync $*\" >> \"$CALLS\"\n\ + set -- $(/bin/cat /proc/$$/stat)\n\ + echo \"$$ ${5}\" > \"$GROUP\"\n", + ); + fixture.command().env("GROUP", &group).output().unwrap() + } + "publish" => fixture + .command() + .env("STUB_PUBLISH_GROUP", &group) + .output() + .unwrap(), + "check" => fixture + .command_with_options(None, None, None, &["--check"]) + .env("STUB_CHECK_GROUP", &group) + .output() + .unwrap(), + _ => unreachable!(), + }; + assert_eq!(code(&output), 0, "{phase} {}", stderr(&output)); + let identity = std::fs::read_to_string(&group).unwrap(); + let (pid, process_group) = identity.trim().split_once(' ').unwrap(); + assert_ne!(pid, process_group, "{phase}"); + assert_eq!(process_group, current_process_group(), "{phase}"); + assert_eq!(output.stdout, b"", "{phase}"); + assert_eq!(output.stderr, b"", "{phase}"); + match phase { + "sync" => {} + "publish" => assert_eq!(fixture.calls().as_bytes(), HISTORICAL_CALLS, "{phase}"), + "check" => assert_eq!( + fixture.calls().as_bytes(), + b"list\ntransaction repo.example\nsync --delete\npublish repo.example\ncheck repo.example\n", + "{phase}" + ), + _ => unreachable!(), + } + } } fn current_process_group() -> String { @@ -912,55 +898,66 @@ fn a_missing_cvmfs_server_is_a_clear_error() { #[test] fn dry_run_prints_every_possible_command_without_running_one() { - let fixture = Fixture::new(); - let output = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) - .args(["--dry-run", "repo.example", "--"]) - .arg(&fixture.sync) - .arg("--delete") - .output() - .unwrap(); - assert_eq!(code(&output), 0, "{}", stderr(&output)); - let stdout = String::from_utf8(output.stdout).unwrap(); - let sync = format!("{} --delete", fixture.sync.display()); - assert_eq!( - stdout.lines().collect::>(), - [ - "cvmfs_server list", - "cvmfs_server transaction repo.example", - &sync, - "cvmfs_server publish repo.example", - "# on sync failure: cvmfs_server abort -f repo.example", - ] - ); - assert!(fixture.calls().is_empty()); -} - -#[test] -fn dry_run_prints_verification_between_sync_and_publish() { - let fixture = Fixture::new(); - let verify = format!("{} --cache 'two words'", fixture.verify.display()); - let output = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) - .args(["--dry-run", "--verify-cmd", &verify, "repo.example", "--"]) - .arg(&fixture.sync) - .arg("--delete") - .output() - .unwrap(); - assert_eq!(code(&output), 0, "{}", stderr(&output)); - let stdout = String::from_utf8(output.stdout).unwrap(); - let sync = format!("{} --delete", fixture.sync.display()); - let verifier = format!("{} --cache 'two words'", fixture.verify.display()); - assert_eq!( - stdout.lines().collect::>(), - [ - "cvmfs_server list", - "cvmfs_server transaction repo.example", - &sync, - &verifier, - "cvmfs_server publish repo.example", - "# on sync or verification failure: cvmfs_server abort -f repo.example", - ] - ); - assert!(fixture.calls().is_empty()); + for case in ["commands", "verify", "tags"] { + let fixture = Fixture::new(); + let sync = format!("{} --delete", fixture.sync.display()); + let verify = format!("{} --cache 'two words'", fixture.verify.display()); + let extra: Vec<&str> = match case { + "commands" => vec![], + "verify" => vec!["--verify-cmd", &verify], + "tags" => vec![ + "--tag", + "snapshot", + "--tag-description", + "two words", + "--check", + ], + _ => unreachable!(), + }; + let expected: Vec = match case { + "commands" => vec![ + "cvmfs_server list".into(), + "cvmfs_server transaction repo.example".into(), + sync.clone(), + "cvmfs_server publish repo.example".into(), + "# on sync failure: cvmfs_server abort -f repo.example".into(), + ], + "verify" => vec![ + "cvmfs_server list".into(), + "cvmfs_server transaction repo.example".into(), + sync.clone(), + verify.clone(), + "cvmfs_server publish repo.example".into(), + "# on sync or verification failure: cvmfs_server abort -f repo.example".into(), + ], + "tags" => vec![ + "cvmfs_server list".into(), + "cvmfs_server transaction repo.example".into(), + sync.clone(), + "cvmfs_server publish -a snapshot -m 'two words' repo.example".into(), + "cvmfs_server check repo.example".into(), + "# on sync failure: cvmfs_server abort -f repo.example".into(), + ], + _ => unreachable!(), + }; + let output = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) + .arg("--dry-run") + .args(&extra) + .arg("repo.example") + .arg("--") + .arg(&fixture.sync) + .arg("--delete") + .output() + .unwrap(); + assert_eq!(code(&output), 0, "{case} {}", stderr(&output)); + let stdout = String::from_utf8(output.stdout).unwrap(); + assert_eq!( + stdout.lines().collect::>(), + expected.iter().map(String::as_str).collect::>(), + "{case}" + ); + assert!(fixture.calls().is_empty(), "{case}"); + } } fn historical_dry_run(sync: &str) -> Vec { @@ -1317,41 +1314,6 @@ fn check_failure_returns_its_status_after_publish() { ); } -#[test] -fn tag_options_appear_in_dry_run_publish_and_check_order() { - let fixture = Fixture::new(); - let output = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) - .args([ - "--dry-run", - "--tag", - "snapshot", - "--tag-description", - "two words", - "--check", - "repo.example", - "--", - ]) - .arg(&fixture.sync) - .arg("--delete") - .output() - .unwrap(); - assert_eq!(code(&output), 0, "{}", stderr(&output)); - let stdout = String::from_utf8(output.stdout).unwrap(); - let sync = format!("{} --delete", fixture.sync.display()); - assert_eq!( - stdout.lines().collect::>(), - [ - "cvmfs_server list", - "cvmfs_server transaction repo.example", - &sync, - "cvmfs_server publish -a snapshot -m 'two words' repo.example", - "cvmfs_server check repo.example", - "# on sync failure: cvmfs_server abort -f repo.example", - ] - ); - assert!(fixture.calls().is_empty()); -} - #[test] fn invalid_arguments_are_usage_errors() { for args in [ @@ -1468,27 +1430,6 @@ fn concurrent_fixture_exec_writes_do_not_hit_text_file_busy() { } } -#[test] -fn cvmfs_dry_run_succeeds_when_stdout_consumer_closes() { - let mut fds = [0; 2]; - unsafe { - assert_eq!(libc::pipe(fds.as_mut_ptr()), 0); - assert_eq!(libc::close(fds[0]), 0); - } - let closed = unsafe { ::from_raw_fd(fds[1]) }; - let o = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) - .args(["--dry-run", "repo.example", "--", "sync"]) - .stdout(closed) - .output() - .unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{}", - String::from_utf8_lossy(&o.stderr) - ); -} - #[test] fn archive_manifest_accepts_equals_form_and_rejects_empty_or_duplicate() { let fixture = Fixture::new(); diff --git a/tests/gap.rs b/tests/gap.rs index 9dfa145e..f5a23dcf 100644 --- a/tests/gap.rs +++ b/tests/gap.rs @@ -3,8 +3,8 @@ mod common; -use common::{closed_stdout, code, eb_pipeline, setup, stderr, stdout, write_exec}; -use std::process::{Command, Stdio}; +use common::{code, eb_pipeline, setup, stderr, stdout, write_exec}; +use std::process::Command; const EB_STACK_GAP: &str = r#"#!/bin/sh echo "$*" >> "$STUB_DIR/gap.calls" @@ -287,36 +287,3 @@ fn a_gap_failure_stops_before_shadow() { assert_eq!(t.calls("gap").lines().count(), 1); assert!(!out_dir.join("shadow.json").exists()); } - -#[test] -fn a_closed_gap_output_consumer_does_not_fail_check() { - let t = configured(); - let out_dir = t.root().join("gap-report"); - let path = format!( - "{}:{}", - t.stubs.display(), - std::env::var("PATH").unwrap_or_default() - ); - let output = Command::new(env!("CARGO_BIN_EXE_eb-pipeline")) - .args([ - "check", - "--site", - &t.site.display().to_string(), - "--gap-out", - &out_dir.display().to_string(), - "--generation", - "2026.1", - ]) - .env("PATH", path) - .env("STUB_DIR", t.root()) - .env("GAP_BASE", "/base/accel") - .env("STUB_GAP_LARGE_OUTPUT", "1") - .stdin(Stdio::null()) - .stdout(closed_stdout()) - .stderr(Stdio::piped()) - .output() - .unwrap(); - - assert_eq!(code(&output), 0, "{}", stderr(&output)); - assert!(out_dir.join("gap.stdout.log").is_file()); -} diff --git a/tests/junit.rs b/tests/junit.rs index 0e653481..0fca942a 100644 --- a/tests/junit.rs +++ b/tests/junit.rs @@ -47,8 +47,30 @@ fn help_and_version_exit_zero() { assert!(text.starts_with("eb-junit "), "{text}"); } -#[test] -fn malformed_inputs_name_their_producers_and_paths() { +fn assert_invalid_json( + output: &std::process::Output, + producer: &str, + path: &std::path::Path, + empty_stdout: bool, +) { + assert_eq!( + output.status.code(), + Some(2), + "{}", + String::from_utf8_lossy(&output.stderr) + ); + if empty_stdout { + assert_eq!(output.stdout, b""); + } + let stderr = String::from_utf8_lossy(&output.stderr); + let shown = path.display().to_string(); + assert!( + stderr.contains(producer) && stderr.contains(&shown) && stderr.contains("invalid JSON"), + "{stderr}" + ); +} + +fn junit_malformed() { let dir = tempfile::tempdir().unwrap(); for (flag, name, producer) in [ ("--result", "result.json", "eb-pipeline run"), @@ -56,18 +78,155 @@ fn malformed_inputs_name_their_producers_and_paths() { ] { let path = dir.path().join(name); std::fs::write(&path, "{").unwrap(); - let output = bin().arg(flag).arg(&path).output().unwrap(); + assert_invalid_json(&output, producer, &path, true); + } +} - assert_eq!(output.status.code(), Some(2)); - assert_eq!(output.stdout, b""); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - format!( - "eb-junit: {producer} wrote invalid JSON to {}: EOF while parsing an object at line 1 column 1\n", - path.display() - ) - ); +fn shard_weights_malformed() { + for (flag, name) in [("--result", "result.json"), ("--summary", "summary.json")] { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join(name); + std::fs::write(&path, "{").unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-shard-weights")) + .arg(flag) + .arg(&path) + .env_remove("EB_PIPELINE_RESULT") + .env_remove("EB_PIPELINE_TARGET") + .output() + .unwrap(); + assert_invalid_json(&output, "eb-pipeline run", &path, true); + } +} + +fn metrics_malformed() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("result.json"); + std::fs::write(&path, "{").unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-pipeline")) + .args(["metrics", "--result"]) + .arg(&path) + .output() + .unwrap(); + assert_invalid_json(&output, "eb-pipeline run", &path, false); +} + +fn package_plan_malformed() { + let root = tempfile::tempdir().unwrap(); + let root_path = root.path().display().to_string(); + let bundle = root.path().join("bundle"); + std::fs::create_dir_all(&bundle).unwrap(); + let manifest = bundle.join("package.plan.json"); + std::fs::write(&manifest, "{").unwrap(); + let site = root.path().join("site.toml"); + std::fs::write( + &site, + format!( + "\ +schema_version = 1 +kind = \"site\" +[site] +name = \"t\" +[scheduler] +kind = \"local\" +[[targets]] +name = \"cpu\" +[filesystems] +scratch = \"{root_path}/scratch\" +tmp = \"{root_path}/tmp\" +build_path = \"{root_path}/build\" +install_root = \"{root_path}/install\" +log_root = \"{root_path}/logs\" +[modules] +init = [] +" + ), + ) + .unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-pipeline")) + .args(["plan", "--site"]) + .arg(&site) + .args(["--package-plan"]) + .arg(&bundle) + .args([ + "--target", + "cpu", + "--build-type", + "production", + "--run-id", + "package-plan", + "--log-stamp", + "20261117_120000", + ]) + .output() + .unwrap(); + assert_invalid_json(&output, "eb-stack package plan", &manifest, false); +} + +fn attest_verify_malformed() { + let root = tempfile::tempdir().unwrap(); + let root_path = root.path().display().to_string(); + std::fs::create_dir_all(root.path().join("easyconfigs")).unwrap(); + std::fs::write(root.path().join("key.pem"), "k\n").unwrap(); + let site = root.path().join("site.toml"); + std::fs::write( + &site, + format!( + "\ +schema_version = 1 +kind = \"site\" +[site] +name = \"t\" +[scheduler] +kind = \"local\" +[[targets]] +name = \"cpu\" +[filesystems] +scratch = \"{root_path}/scratch\" +tmp = \"{root_path}/tmp\" +build_path = \"{root_path}/build\" +install_root = \"{root_path}/install\" +log_root = \"{root_path}/logs\" +[modules] +init = [] + +[attest] +enabled = true +log_dir = \"{root_path}/log\" +key = \"{root_path}/key.pem\" +origin = \"example.org/inputs\" +trusted = [\"example.org/inputs+abcd+AAAA\"] +easyconfigs = [\"{root_path}/easyconfigs\"] +" + ), + ) + .unwrap(); + let list = root.path().join("list.txt"); + std::fs::write(&list, "Foo-1.0.eb\n").unwrap(); + let from = root.path().join("plan.json"); + std::fs::write(&from, "{").unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-pipeline")) + .args(["verify", "--site"]) + .arg(&site) + .args(["--list"]) + .arg(&list) + .args(["--target", "cpu", "--build-type", "production", "--from"]) + .arg(&from) + .output() + .unwrap(); + assert_invalid_json(&output, "eb-pipeline plan", &from, false); +} + +#[test] +fn malformed_inputs_name_their_producers_and_paths() { + for row in [ + junit_malformed as fn(), + shard_weights_malformed, + metrics_malformed, + package_plan_malformed, + attest_verify_malformed, + ] { + row(); } } @@ -503,35 +662,6 @@ fn the_pages_name_eb_junit() { assert!(reference.contains("\n junit\n"), "{reference}"); } -#[test] -fn junit_succeeds_when_stdout_consumer_closes() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("result.json"); - std::fs::write( - &path, - r#"{"kind":"result","schema_version":1,"site":"s","target":"t","build_type":"b","run_id":"r","exit_code":0,"lines":[]}"#, - ) - .unwrap(); - let mut fds = [0; 2]; - unsafe { - assert_eq!(libc::pipe(fds.as_mut_ptr()), 0); - assert_eq!(libc::close(fds[0]), 0); - } - let closed = unsafe { ::from_raw_fd(fds[1]) }; - let o = bin() - .args(["--result"]) - .arg(&path) - .stdout(closed) - .output() - .unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{}", - String::from_utf8_lossy(&o.stderr) - ); -} - #[test] fn value_options_do_not_consume_the_next_long_option() { let output = bin() diff --git a/tests/metrics.rs b/tests/metrics.rs index e86beae0..3bebbd9e 100644 --- a/tests/metrics.rs +++ b/tests/metrics.rs @@ -67,28 +67,6 @@ fn metrics_prints_prometheus_for_a_failed_run() { ); } -#[test] -fn malformed_result_names_the_producer_and_path() { - let dir = tempfile::tempdir().unwrap(); - let path = dir.path().join("result.json"); - std::fs::write(&path, "{").unwrap(); - - let output = bin() - .args(["metrics", "--result"]) - .arg(&path) - .output() - .unwrap(); - - assert_eq!(output.status.code(), Some(2)); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - format!( - "ERROR [main] -: eb-pipeline run wrote invalid JSON to {}: EOF while parsing an object at line 1 column 1\n", - path.display() - ) - ); -} - #[test] fn metrics_json_is_a_status_and_a_plan_is_refused() { let dir = tempfile::tempdir().unwrap(); diff --git a/tests/package_plan.rs b/tests/package_plan.rs index 40255ed3..99b66de6 100644 --- a/tests/package_plan.rs +++ b/tests/package_plan.rs @@ -154,24 +154,6 @@ fn plan_builds_declared_recipes_and_records_the_manifest_digest() { assert_eq!(verification["reason"], "not requested"); } -#[test] -fn truncated_package_plan_reports_the_producer_and_path() { - let fixture = fixture("pypi", "demo", "demo-1.0-GCCcore-15.2.0.eb"); - let manifest = fixture.bundle.join("package.plan.json"); - std::fs::write(&manifest, "{").unwrap(); - - let output = command(&fixture, "plan").output().unwrap(); - - assert_eq!(output.status.code(), Some(2)); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - format!( - "ERROR [main] -: eb-stack package plan wrote invalid JSON to {}: EOF while parsing an object at line 1 column 1\n", - manifest.display() - ) - ); -} - #[test] fn verification_is_opt_in_and_runs_pip_check_with_the_product_module() { let fixture = fixture("pypi", "demo", "demo-1.0-GCCcore-15.2.0.eb"); diff --git a/tests/retry_list.rs b/tests/retry_list.rs index 7e984c56..af4429e5 100644 --- a/tests/retry_list.rs +++ b/tests/retry_list.rs @@ -1803,39 +1803,6 @@ fn duplicate_single_value_flags_are_refused() { } } -#[test] -fn retry_list_succeeds_when_stdout_consumer_closes() { - let dir = tempfile::tempdir().unwrap(); - let list = dir.path().join("list.txt"); - std::fs::write(&list, "Want.eb\n").unwrap(); - let result = dir.path().join("result.json"); - std::fs::write( - &result, - r#"{"kind":"result","exit_code":1,"lines":[{"easyconfig":"Want.eb","status":"failed"}]}"#, - ) - .unwrap(); - let mut fds = [0; 2]; - unsafe { - assert_eq!(libc::pipe(fds.as_mut_ptr()), 0); - assert_eq!(libc::close(fds[0]), 0); - } - let closed = unsafe { ::from_raw_fd(fds[1]) }; - let o = bin() - .args(["--result"]) - .arg(&result) - .args(["--list"]) - .arg(&list) - .stdout(closed) - .output() - .unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{}", - String::from_utf8_lossy(&o.stderr) - ); -} - #[test] fn value_options_do_not_consume_the_next_long_option() { let output = bin() diff --git a/tests/sbom.rs b/tests/sbom.rs index 2061de5d..a40e13a8 100644 --- a/tests/sbom.rs +++ b/tests/sbom.rs @@ -111,36 +111,24 @@ fn a_success_without_a_new_document_does_not_accept_a_stale_one() { #[test] fn a_success_with_an_empty_document_fails_the_run() { - let t = setup("[sbom]\nlock = \"@ROOT@/stack.lock.json\"\n"); - write_exec(&t.stubs.join("eb-stack"), EMPTY_SBOM); - let output = run(&t, "cpu", STAMP, LIST, &[]); - let document = t.run_dir(STAMP).join("sbom.cdx.json"); - - assert_eq!(code(&output), 1, "{}", stderr(&output)); - assert!( - stderr(&output).contains("wrote no non-empty"), - "{}", - stderr(&output) - ); - assert!(!document.exists()); - assert_eq!(t.summary(STAMP)["exit_code"], 1); -} - -#[test] -fn a_success_with_truncated_json_fails_the_run() { - let t = setup("[sbom]\nlock = \"@ROOT@/stack.lock.json\"\n"); - write_exec(&t.stubs.join("eb-stack"), TRUNCATED_SBOM); - let output = run(&t, "cpu", STAMP, LIST, &[]); - let document = t.run_dir(STAMP).join("sbom.cdx.json"); + for (stub, phrase) in [ + (EMPTY_SBOM, "wrote no non-empty"), + (TRUNCATED_SBOM, "wrote invalid JSON"), + ] { + let t = setup("[sbom]\nlock = \"@ROOT@/stack.lock.json\"\n"); + write_exec(&t.stubs.join("eb-stack"), stub); + let output = run(&t, "cpu", STAMP, LIST, &[]); + let document = t.run_dir(STAMP).join("sbom.cdx.json"); - assert_eq!(code(&output), 1, "{}", stderr(&output)); - assert!( - stderr(&output).contains("wrote invalid JSON"), - "{}", - stderr(&output) - ); - assert!(!document.exists()); - assert_eq!(t.summary(STAMP)["exit_code"], 1); + assert_eq!(code(&output), 1, "{phrase} {}", stderr(&output)); + assert!( + stderr(&output).contains(phrase), + "{phrase} {}", + stderr(&output) + ); + assert!(!document.exists(), "{phrase}"); + assert_eq!(t.summary(STAMP)["exit_code"], 1, "{phrase}"); + } } #[test] diff --git a/tests/shard_weights.rs b/tests/shard_weights.rs index 097f1972..6539ec09 100644 --- a/tests/shard_weights.rs +++ b/tests/shard_weights.rs @@ -49,94 +49,34 @@ fn successful_build_durations_become_sorted_tab_separated_weights() { ); } -#[test] -fn malformed_result_names_the_producer_and_path() { - let dir = tempfile::tempdir().unwrap(); - let result = dir.path().join("result.json"); - std::fs::write(&result, "{").unwrap(); - - let output = bin().args(["--result"]).arg(&result).output().unwrap(); - - assert_eq!(output.status.code(), Some(2)); - assert_eq!(output.stdout, b""); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - format!( - "eb-shard-weights: eb-pipeline run wrote invalid JSON to {}: EOF while parsing an object at line 1 column 1\n", - result.display() - ) - ); -} - #[test] fn a_duration_beyond_any_integer_weight_is_refused() { - let dir = tempfile::tempdir().unwrap(); - let result = dir.path().join("result.json"); - std::fs::write( - &result, - r#"{"kind":"result","target":"cpu","lines":[{"easyconfig":"Foo-1.0.eb","phase":"build","status":"success","duration_seconds":1e300}]}"#, - ) - .unwrap(); - - let output = bin() - .args(["--result"]) - .arg(&result) - .args(["--target", "cpu"]) - .output() - .unwrap(); - - assert_eq!(output.status.code(), Some(2)); - assert_eq!(output.stdout, b""); - let stderr = String::from_utf8_lossy(&output.stderr); - assert!( - stderr.contains("lines[0].duration_seconds exceeds"), - "{stderr}" - ); -} - -#[test] -fn a_duration_at_exactly_two_to_the_sixty_fourth_is_refused() { - let dir = tempfile::tempdir().unwrap(); - let result = dir.path().join("result.json"); - std::fs::write( - &result, - r#"{"kind":"result","target":"cpu","lines":[{"easyconfig":"Foo-1.0.eb","phase":"build","status":"success","duration_seconds":18446744073709551616.0}]}"#, - ) - .unwrap(); - - let output = bin() - .args(["--result"]) - .arg(&result) - .args(["--target", "cpu"]) - .output() + for duration in ["1e300", "18446744073709551616.0"] { + let dir = tempfile::tempdir().unwrap(); + let result = dir.path().join("result.json"); + std::fs::write( + &result, + format!( + r#"{{"kind":"result","target":"cpu","lines":[{{"easyconfig":"Foo-1.0.eb","phase":"build","status":"success","duration_seconds":{duration}}}]}}"# + ), + ) .unwrap(); - assert_eq!(output.status.code(), Some(2)); - assert_eq!(output.stdout, b""); - let stderr = String::from_utf8_lossy(&output.stderr); - assert!( - stderr.contains("lines[0].duration_seconds exceeds"), - "{stderr}" - ); -} - -#[test] -fn malformed_summary_names_the_producer_and_path() { - let dir = tempfile::tempdir().unwrap(); - let summary = dir.path().join("summary.json"); - std::fs::write(&summary, "{").unwrap(); - - let output = bin().args(["--summary"]).arg(&summary).output().unwrap(); + let output = bin() + .args(["--result"]) + .arg(&result) + .args(["--target", "cpu"]) + .output() + .unwrap(); - assert_eq!(output.status.code(), Some(2)); - assert_eq!(output.stdout, b""); - assert_eq!( - String::from_utf8_lossy(&output.stderr), - format!( - "eb-shard-weights: eb-pipeline run wrote invalid JSON to {}: EOF while parsing an object at line 1 column 1\n", - summary.display() - ) - ); + assert_eq!(output.status.code(), Some(2), "{duration}"); + assert_eq!(output.stdout, b"", "{duration}"); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!( + stderr.contains("lines[0].duration_seconds exceeds"), + "{duration} {stderr}" + ); + } } #[test] @@ -629,35 +569,6 @@ fn duplicate_single_value_flags_are_refused() { } } -#[test] -fn shard_weights_succeeds_when_stdout_consumer_closes() { - let dir = tempfile::tempdir().unwrap(); - let result = dir.path().join("result.json"); - std::fs::write( - &result, - r#"{"kind":"result","target":"cpu","lines":[{"easyconfig":"A-1.0.eb","phase":"build","status":"success","duration_seconds":1.0}]}"#, - ) - .unwrap(); - let mut fds = [0; 2]; - unsafe { - assert_eq!(libc::pipe(fds.as_mut_ptr()), 0); - assert_eq!(libc::close(fds[0]), 0); - } - let closed = unsafe { ::from_raw_fd(fds[1]) }; - let o = bin() - .args(["--result"]) - .arg(&result) - .stdout(closed) - .output() - .unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{}", - String::from_utf8_lossy(&o.stderr) - ); -} - #[test] fn a_target_filter_must_match_an_input_target() { let dir = tempfile::tempdir().unwrap(); diff --git a/tests/stack_checks.rs b/tests/stack_checks.rs index 8f8d5c29..4b511cb6 100644 --- a/tests/stack_checks.rs +++ b/tests/stack_checks.rs @@ -200,56 +200,51 @@ fn stack_checks_require_a_list_and_validate_the_target_before_starting() { #[test] fn easystack_checks_refuse_a_plain_build_list() { - let t = configured(); - let list = t.root().join("build.list"); - std::fs::write(&list, "Pkg-1.0.eb\n").unwrap(); - let output = eb_pipeline( - &t, - &[ - "check", - "--site", - &t.site.display().to_string(), - "--list", - &list.display().to_string(), - "--stack-checks", + let rows = [ + ( + "build.list", + "Pkg-1.0.eb\n", "generation", - ], - &[], - ); - assert_eq!(code(&output), 2, "{}", stderr(&output)); - assert!(t.calls("ebstack").is_empty()); - assert!( - stderr(&output).contains("needs an easystack .yml or .yaml path"), - "{}", - stderr(&output) - ); -} - -#[test] -fn provided_cannot_share_an_input_with_easystack_checks() { - let t = configured(); - let list = t.root().join("stack.yml"); - std::fs::write(&list, "easyconfigs: []\n").unwrap(); - let output = eb_pipeline( - &t, - &[ - "check", - "--site", - &t.site.display().to_string(), - "--list", - &list.display().to_string(), - "--stack-checks", + "needs an easystack .yml or .yaml path", + ), + ( + "stack.yml", + "easyconfigs: []\n", "provided,files", - ], - &[], - ); - assert_eq!(code(&output), 2, "{}", stderr(&output)); - assert!(t.calls("ebstack").is_empty()); - assert!( - stderr(&output).contains("cannot combine provided with easystack checks"), - "{}", - stderr(&output) - ); + "cannot combine provided with easystack checks", + ), + ( + "stack.yml", + "easyconfigs: []\n", + "generation,buildenv,provided", + "cannot combine buildenv and provided with easystack checks", + ), + ]; + for (name, body, checks, phrase) in rows { + let t = configured(); + let list = t.root().join(name); + std::fs::write(&list, body).unwrap(); + let output = eb_pipeline( + &t, + &[ + "check", + "--site", + &t.site.display().to_string(), + "--list", + &list.display().to_string(), + "--stack-checks", + checks, + ], + &[], + ); + assert_eq!(code(&output), 2, "{phrase} {}", stderr(&output)); + assert!(t.calls("ebstack").is_empty(), "{phrase}"); + assert!( + stderr(&output).contains(phrase), + "{phrase} {}", + stderr(&output) + ); + } } #[test] @@ -362,30 +357,3 @@ fn plain_list_checks_run_together_on_one_build_list() { + "\n"; assert_eq!(t.calls("ebstack"), expected); } - -#[test] -fn buildenv_cannot_share_an_input_with_easystack_checks() { - let t = configured(); - let list = t.root().join("stack.yml"); - std::fs::write(&list, "easyconfigs: []\n").unwrap(); - let output = eb_pipeline( - &t, - &[ - "check", - "--site", - &t.site.display().to_string(), - "--list", - &list.display().to_string(), - "--stack-checks", - "generation,buildenv,provided", - ], - &[], - ); - assert_eq!(code(&output), 2, "{}", stderr(&output)); - assert!(t.calls("ebstack").is_empty()); - assert!( - stderr(&output).contains("cannot combine buildenv and provided with easystack checks"), - "{}", - stderr(&output) - ); -} diff --git a/tests/standalone_output.rs b/tests/standalone_output.rs index 3d0b3ef1..67aee7cf 100644 --- a/tests/standalone_output.rs +++ b/tests/standalone_output.rs @@ -1,21 +1,34 @@ -//! Standalone command metadata output follows the CLI broken-pipe contract. +//! Standalone command output follows the CLI broken-pipe contract. +#![allow(clippy::disallowed_methods)] -use std::os::fd::FromRawFd; +mod common; + +use common::closed_stdout; use std::process::{Command, Stdio}; -fn closed_stdout() -> Stdio { - let mut fds = [0; 2]; - // SAFETY: both descriptors are checked, and ownership of the write - // descriptor moves into `Stdio`. - unsafe { - assert_eq!(libc::pipe(fds.as_mut_ptr()), 0); - assert_eq!(libc::close(fds[0]), 0); - Stdio::from_raw_fd(fds[1]) - } -} +const GAP_EB_STACK: &str = r#"#!/bin/sh +echo "$*" >> "$STUB_DIR/gap.calls" +case "$1 $2" in + "stack gap") + while [ "$#" -gt 0 ]; do + if [ "$1" = "--out-dir" ]; then out=$2; shift; fi + shift + done + mkdir -p "$out" + printf 'route\tname\nrecipe\tLocal\n' > "$out/gap.tsv" + printf 'Local-1.0-GCCcore-15.2.0.eb\n' > "$out/roots.txt" + echo "gap warning" >&2 + if [ -n "${STUB_GAP_LARGE_OUTPUT:-}" ]; then + dd if=/dev/zero bs=65536 count=2 2>/dev/null | tr '\0' x + fi + echo "site=1 in-stack=0 filtered=0 open-layer=0 recipe=1 open-easyconfigs=0 no-recipe=0 excluded=0 out=$out" + exit "${STUB_GAP_EXIT:-0}" + ;; +esac +exit 2 +"#; -#[test] -fn standalone_help_and_version_tolerate_a_closed_consumer() { +fn help_and_version() { for binary in [ env!("CARGO_BIN_EXE_eb-cvmfs"), env!("CARGO_BIN_EXE_eb-junit"), @@ -39,3 +52,209 @@ fn standalone_help_and_version_tolerate_a_closed_consumer() { } } } + +fn shard_weights_closed() { + let dir = tempfile::tempdir().unwrap(); + let result = dir.path().join("result.json"); + std::fs::write( + &result, + r#"{"kind":"result","target":"cpu","lines":[{"easyconfig":"A-1.0.eb","phase":"build","status":"success","duration_seconds":1.0}]}"#, + ) + .unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-shard-weights")) + .args(["--result"]) + .arg(&result) + .env_remove("EB_PIPELINE_RESULT") + .env_remove("EB_PIPELINE_TARGET") + .stdout(closed_stdout()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "eb-shard-weights: {}", + String::from_utf8_lossy(&output.stderr) + ); +} + +fn test_map_closed(format: &str) { + let dir = tempfile::tempdir().unwrap(); + let map = dir.path().join("map.tsv"); + std::fs::write(&map, "G g\n").unwrap(); + let list = dir.path().join("l.txt"); + std::fs::write(&list, "G-1.0.eb\n").unwrap(); + let mut cmd = Command::new(env!("CARGO_BIN_EXE_eb-test-map")); + cmd.args(["--list"]).arg(&list).args(["--format", format]); + if format != "eessi-modules" { + cmd.args(["--map"]).arg(&map); + } + let output = cmd + .stdout(closed_stdout()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "eb-test-map {format}: {}", + String::from_utf8_lossy(&output.stderr) + ); +} + +fn test_map_text() { + test_map_closed("text"); +} + +fn test_map_eessi() { + test_map_closed("eessi-modules"); +} + +fn junit_closed() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("result.json"); + std::fs::write( + &path, + r#"{"kind":"result","schema_version":1,"site":"s","target":"t","build_type":"b","run_id":"r","exit_code":0,"lines":[]}"#, + ) + .unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-junit")) + .args(["--result"]) + .arg(&path) + .env_remove("EB_PIPELINE_RESULT") + .stdout(closed_stdout()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "eb-junit: {}", + String::from_utf8_lossy(&output.stderr) + ); +} + +fn retry_list_closed() { + let dir = tempfile::tempdir().unwrap(); + let list = dir.path().join("list.txt"); + std::fs::write(&list, "Want.eb\n").unwrap(); + let result = dir.path().join("result.json"); + std::fs::write( + &result, + r#"{"kind":"result","exit_code":1,"lines":[{"easyconfig":"Want.eb","status":"failed"}]}"#, + ) + .unwrap(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-retry-list")) + .args(["--result"]) + .arg(&result) + .args(["--list"]) + .arg(&list) + .env_remove("EB_PIPELINE_RESULT") + .env_remove("EB_PIPELINE_LIST") + .env_remove("EB_PIPELINE_TARGET") + .stdout(closed_stdout()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "eb-retry-list: {}", + String::from_utf8_lossy(&output.stderr) + ); +} + +fn cvmfs_dry_run_closed() { + let output = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) + .args(["--dry-run", "repo.example", "--", "sync"]) + .stdout(closed_stdout()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "eb-cvmfs: {}", + String::from_utf8_lossy(&output.stderr) + ); +} + +fn gap_closed() { + let t = common::setup( + r#" +[shards] +enabled = false +easyconfigs = ["/recipes/local"] +installed_modules_dirs = ["/base/cpu"] +installed_modules_dirs_from_env = ["GAP_BASE"] +[watch] +enabled = false +modules_dirs = ["/base/cpu", "/base/gpu"] +easyconfigs = ["/recipes/local", "/recipes/extra"] +"#, + ); + common::write_exec(&t.stubs.join("eb-stack"), GAP_EB_STACK); + let text = std::fs::read_to_string(&t.site) + .unwrap() + .replacen( + "name = \"cpu\"", + "name = \"cpu\"\nmodules_root = \"/local/cpu/modules\"", + 1, + ) + .replacen( + "name = \"gpu\"", + "name = \"gpu\"\nmodules_root = \"/local/gpu/modules\"", + 1, + ); + std::fs::write(&t.site, text).unwrap(); + let out_dir = t.root().join("gap-report"); + let path = format!( + "{}:{}", + t.stubs.display(), + std::env::var("PATH").unwrap_or_default() + ); + let site = t.site.display().to_string(); + let out = out_dir.display().to_string(); + let output = Command::new(env!("CARGO_BIN_EXE_eb-pipeline")) + .args([ + "check", + "--site", + &site, + "--gap-out", + &out, + "--generation", + "2026.1", + ]) + .env("PATH", path) + .env("STUB_DIR", t.root()) + .env("GAP_BASE", "/base/accel") + .env("STUB_GAP_LARGE_OUTPUT", "1") + .stdin(Stdio::null()) + .stdout(closed_stdout()) + .stderr(Stdio::piped()) + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "check --gap-out: {}", + String::from_utf8_lossy(&output.stderr) + ); + assert!(out_dir.join("gap.stdout.log").is_file()); +} + +#[test] +fn standalone_help_and_version_tolerate_a_closed_consumer() { + for row in [ + help_and_version as fn(), + shard_weights_closed, + test_map_text, + test_map_eessi, + junit_closed, + retry_list_closed, + cvmfs_dry_run_closed, + gap_closed, + ] { + row(); + } +} diff --git a/tests/test_map.rs b/tests/test_map.rs index 11890bc7..1ff5b7e3 100644 --- a/tests/test_map.rs +++ b/tests/test_map.rs @@ -490,70 +490,39 @@ fn include_resumed_requires_result_input() { #[test] fn reframe_output_escapes_regex_metacharacters() { - let dir = tempfile::tempdir().unwrap(); - std::fs::write( - dir.path().join("map.tsv"), - "GROMACS gromacs+gpu(v2)\n".as_bytes(), - ) - .unwrap(); - std::fs::write( - dir.path().join("build.list"), - "GROMACS-2024.1-foss-2023b.eb\n".as_bytes(), - ) - .unwrap(); - let o = bin() - .arg("--map") - .arg(dir.path().join("map.tsv")) - .arg("--list") - .arg(dir.path().join("build.list")) - .arg("--format") - .arg("reframe") - .output() - .unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{}", - String::from_utf8_lossy(&o.stderr) - ); - assert_eq!( - String::from_utf8(o.stdout).unwrap(), - "-n ^gromacs\\+gpu\\(v2\\)$\n" - ); -} - -#[test] -fn reframe_output_escapes_dot_and_libstdcpp() { - let dir = tempfile::tempdir().unwrap(); - std::fs::write( - dir.path().join("map.tsv"), - "GROMACS gromacs.2024\nFFTW libstdc++\n".as_bytes(), - ) - .unwrap(); - std::fs::write( - dir.path().join("build.list"), - "GROMACS-2024.1-foss-2023b.eb\nFFTW-3.3.10-GCC-13.2.0.eb\n".as_bytes(), - ) - .unwrap(); - let o = bin() - .arg("--map") - .arg(dir.path().join("map.tsv")) - .arg("--list") - .arg(dir.path().join("build.list")) - .arg("--format") - .arg("reframe") - .output() - .unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{}", - String::from_utf8_lossy(&o.stderr) - ); - assert_eq!( - String::from_utf8(o.stdout).unwrap(), - "-n ^gromacs\\.2024$\n-n ^libstdc\\+\\+$\n" - ); + let rows = [ + ( + "GROMACS gromacs+gpu(v2)\n", + "GROMACS-2024.1-foss-2023b.eb\n", + "-n ^gromacs\\+gpu\\(v2\\)$\n", + ), + ( + "GROMACS gromacs.2024\nFFTW libstdc++\n", + "GROMACS-2024.1-foss-2023b.eb\nFFTW-3.3.10-GCC-13.2.0.eb\n", + "-n ^gromacs\\.2024$\n-n ^libstdc\\+\\+$\n", + ), + ]; + for (map, list, want) in rows { + let dir = tempfile::tempdir().unwrap(); + std::fs::write(dir.path().join("map.tsv"), map.as_bytes()).unwrap(); + std::fs::write(dir.path().join("build.list"), list.as_bytes()).unwrap(); + let output = bin() + .arg("--map") + .arg(dir.path().join("map.tsv")) + .arg("--list") + .arg(dir.path().join("build.list")) + .arg("--format") + .arg("reframe") + .output() + .unwrap(); + assert_eq!( + output.status.code(), + Some(0), + "{map} {}", + String::from_utf8_lossy(&output.stderr) + ); + assert_eq!(String::from_utf8(output.stdout).unwrap(), want, "{map}"); + } } #[test] @@ -643,37 +612,6 @@ fn duplicate_single_value_flags_are_refused() { } } -#[test] -fn test_map_succeeds_when_stdout_consumer_closes() { - let dir = tempfile::tempdir().unwrap(); - let map = dir.path().join("map.tsv"); - std::fs::write(&map, "G g\n").unwrap(); - let list = dir.path().join("l.txt"); - std::fs::write(&list, "G-1.0.eb\n").unwrap(); - - for format in ["text", "eessi-modules"] { - let mut fds = [0; 2]; - unsafe { - assert_eq!(libc::pipe(fds.as_mut_ptr()), 0); - assert_eq!(libc::close(fds[0]), 0); - } - let closed = - unsafe { ::from_raw_fd(fds[1]) }; - let mut cmd = bin(); - cmd.args(["--list"]).arg(&list).args(["--format", format]); - if format != "eessi-modules" { - cmd.args(["--map"]).arg(&map); - } - let o = cmd.stdout(closed).output().unwrap(); - assert_eq!( - o.status.code(), - Some(0), - "{format}: {}", - String::from_utf8_lossy(&o.stderr) - ); - } -} - #[test] fn plain_build_list_options_are_not_part_of_the_easyconfig_name() { let dir = tempfile::tempdir().unwrap(); From f69d8bbe09373e949e626b385f2e713496f9c139 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 12:30:52 +0000 Subject: [PATCH 3/6] test: stub curl for the webhook posts The three webhook tests record the request with a curl stub on `PATH` and return 0, 22, or 7. The token stays out of the log. Rust tests stay 772. --- tests/notify.rs | 120 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 40 deletions(-) diff --git a/tests/notify.rs b/tests/notify.rs index a561729c..3e781392 100644 --- a/tests/notify.rs +++ b/tests/notify.rs @@ -2,7 +2,7 @@ //! server, and never prints the URL past its host. mod common; -use common::{code, eb_pipeline, run, setup, stderr, stdout, STAMP}; +use common::{code, eb_pipeline, run, setup, stderr, stdout, write_exec, STAMP}; use serde_json::Value; use std::io::{Read, Write}; use std::net::{TcpListener, TcpStream}; @@ -13,8 +13,6 @@ const LIST: &str = "Foo-1.0-foss-2025a.eb\n"; const SECRET: &str = "s3cr3t-token"; struct Request { - line: String, - headers: Vec, body: Vec, } @@ -52,9 +50,12 @@ fn read_request(s: &mut TcpStream) -> Request { buf.extend_from_slice(&chunk[..n]); }; let head = String::from_utf8_lossy(&buf[..head_end]).into_owned(); - let mut lines = head.split("\r\n").filter(|l| !l.is_empty()); - let line = lines.next().unwrap_or_default().to_string(); - let headers: Vec = lines.map(str::to_string).collect(); + let headers: Vec = head + .split("\r\n") + .filter(|l| !l.is_empty()) + .skip(1) + .map(str::to_string) + .collect(); let len: usize = headers .iter() .find_map(|h| { @@ -69,8 +70,6 @@ fn read_request(s: &mut TcpStream) -> Request { buf.extend_from_slice(&chunk[..n]); } Request { - line, - headers, body: buf[head_end..head_end + len].to_vec(), } } @@ -92,33 +91,67 @@ fn assert_no_secret(t: &common::T, out: &std::process::Output) { } } +const CURL_STUB: &str = r#"#!/bin/sh +D="${STUB_DIR:?}" +n=$(( $(cat "$D/curl.count" 2>/dev/null || echo 0) + 1 )) +printf '%s\n' "$n" > "$D/curl.count" +printf '%s\0' "$@" > "$D/curl.$n.args" +cat > "$D/curl.$n.stdin" +prev= +for a in "$@"; do + if [ "$prev" = "--data-binary" ]; then + case "$a" in + @*) cp "${a#@}" "$D/curl.$n.body" ;; + esac + fi + prev=$a +done +exit "${STUB_CURL_EXIT:-0}" +"#; + +fn install_curl(t: &common::T) { + write_exec(&t.stubs.join("curl"), CURL_STUB); +} + +fn curl_count(t: &common::T) -> usize { + std::fs::read_to_string(t.root().join("curl.count")) + .ok() + .and_then(|text| text.trim().parse().ok()) + .unwrap_or(0) +} + +fn curl_args(t: &common::T, n: usize) -> Vec { + let bytes = std::fs::read(t.root().join(format!("curl.{n}.args"))).unwrap_or_default(); + bytes + .split(|byte| *byte == 0) + .filter(|part| !part.is_empty()) + .map(|part| String::from_utf8(part.to_vec()).unwrap()) + .collect() +} + #[test] fn a_run_posts_its_summary_to_the_webhook() { - let (port, rx) = serve("200 OK"); let t = setup("[notify]\nwebhook_env = \"EB_TEST_WEBHOOK\"\n"); - let url = format!("http://hook:hunter2@127.0.0.1:{port}/hook/{SECRET}?key={SECRET}"); + install_curl(&t); + let url = format!("http://hook:hunter2@hooks.example/hook/{SECRET}?key={SECRET}"); let o = run(&t, "cpu", STAMP, LIST, &[("EB_TEST_WEBHOOK", &url)]); assert_eq!(code(&o), 0, "{}", stderr(&o)); - let req = rx.recv_timeout(Duration::from_secs(10)).unwrap(); - assert_eq!( - req.line, - format!("POST /hook/{SECRET}?key={SECRET} HTTP/1.1") - ); + assert_eq!(curl_count(&t), 1); + let args = curl_args(&t, 1); assert!( - req.headers - .iter() - .any(|h| h.eq_ignore_ascii_case("content-type: application/json")), - "{:?}", - req.headers + args.iter() + .any(|arg| arg.eq_ignore_ascii_case("Content-Type: application/json")), + "{args:?}" ); - let posted: Value = serde_json::from_slice(&req.body).unwrap(); + let body = std::fs::read(t.root().join("curl.1.body")).unwrap(); + let posted: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(posted, t.summary(STAMP)); assert_eq!(posted["kind"], "summary"); assert_eq!(posted["targets"][0]["name"], "cpu"); + let stdin = std::fs::read_to_string(t.root().join("curl.1.stdin")).unwrap(); + assert!(stdin.contains(&url), "{stdin}"); assert!( - stderr(&o).contains(&format!( - "INFO [notify] cpu: summary.json posted to http://127.0.0.1:{port}/...\n" - )), + stderr(&o).contains("INFO [notify] cpu: summary.json posted to http://hooks.example/...\n"), "{}", stderr(&o) ); @@ -127,16 +160,22 @@ fn a_run_posts_its_summary_to_the_webhook() { #[test] fn a_webhook_that_fails_is_a_warning() { - let (port, rx) = serve("500 Internal Server Error"); let t = setup("[notify]\nwebhook_env = \"EB_TEST_WEBHOOK\"\n"); - let url = format!("http://127.0.0.1:{port}/hook/{SECRET}"); - let o = run(&t, "cpu", STAMP, LIST, &[("EB_TEST_WEBHOOK", &url)]); + install_curl(&t); + let url = format!("http://hooks.example/hook/{SECRET}"); + let o = run( + &t, + "cpu", + STAMP, + LIST, + &[("EB_TEST_WEBHOOK", &url), ("STUB_CURL_EXIT", "22")], + ); assert_eq!(code(&o), 0, "{}", stderr(&o)); - assert!(rx.recv_timeout(Duration::from_secs(10)).is_ok()); + assert_eq!(curl_count(&t), 1); assert!( - stderr(&o).contains(&format!( - "WARN [notify] cpu: POST of summary.json to http://127.0.0.1:{port}/... failed: curl exited 22" - )), + stderr(&o).contains( + "WARN [notify] cpu: POST of summary.json to http://hooks.example/... failed: curl exited 22" + ), "{}", stderr(&o) ); @@ -145,25 +184,26 @@ fn a_webhook_that_fails_is_a_warning() { #[test] fn an_unreachable_webhook_is_a_warning() { - let port = { - let l = TcpListener::bind("127.0.0.1:0").unwrap(); - l.local_addr().unwrap().port() - }; let t = setup(&format!( - "[notify]\nwebhook = \"http://127.0.0.1:{port}/{SECRET}\"\ntimeout_seconds = 5\n" + "[notify]\nwebhook = \"http://hooks.example/{SECRET}\"\ntimeout_seconds = 5\n" )); + install_curl(&t); let o = run( &t, "cpu", STAMP, LIST, - &[("STUB_EB_FAIL", "Foo-1.0-foss-2025a")], + &[ + ("STUB_EB_FAIL", "Foo-1.0-foss-2025a"), + ("STUB_CURL_EXIT", "7"), + ], ); assert_eq!(code(&o), 1, "{}", stderr(&o)); + assert_eq!(curl_count(&t), 1); assert!( - stderr(&o).contains(&format!( - "WARN [notify] cpu: POST of summary.json to http://127.0.0.1:{port}/... failed: curl exited 7" - )), + stderr(&o).contains( + "WARN [notify] cpu: POST of summary.json to http://hooks.example/... failed: curl exited 7" + ), "{}", stderr(&o) ); From 2cf926fa9566d800413c1b7b7a10b2aa183b524e Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 13:14:36 +0000 Subject: [PATCH 4/6] test: shrink the atomic-name and fixture loops `write_atomic` tries 2 temporary names under `cfg(test)` and 1000 otherwise. The failure test fills those 2 names and the previous bytes stay. The fixture race runs 2 threads of 2 syncs. Rust tests stay 772. --- src/util.rs | 14 ++++++++++++-- tests/cvmfs.rs | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/util.rs b/src/util.rs index 87806476..e81a869c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -222,6 +222,16 @@ pub fn copy_atomic_checked( ) } +#[cfg(test)] +fn atomic_create_attempts() -> u32 { + 2 +} + +#[cfg(not(test))] +fn atomic_create_attempts() -> u32 { + 1000 +} + fn publish_atomic_with( path: &Path, populate: impl FnOnce(&mut std::fs::File, &Path) -> Result, @@ -244,7 +254,7 @@ fn publish_atomic_with( let name = atomic_output_name(&destination); let local_identity = local_writer_identity(); remove_stale_atomic_temporary_files(parent, name, &local_identity); - for attempt in 0..1000u32 { + for attempt in 0..atomic_create_attempts() { let temporary = parent.join(atomic_temp_file_name( name, &local_identity, @@ -1270,7 +1280,7 @@ mod tests { let path = dir.path().join("result.json"); std::fs::write(&path, b"complete old bytes\n").unwrap(); let identity = local_writer_identity(); - for attempt in 0..1000u32 { + for attempt in 0..atomic_create_attempts() { std::fs::write( dir.path().join(atomic_temp_file_name( "result.json", diff --git a/tests/cvmfs.rs b/tests/cvmfs.rs index c90bfc5c..735ba0a4 100644 --- a/tests/cvmfs.rs +++ b/tests/cvmfs.rs @@ -1414,10 +1414,10 @@ fn invalid_arguments_are_usage_errors() { #[test] fn concurrent_fixture_exec_writes_do_not_hit_text_file_busy() { - let workers: Vec<_> = (0..8) + let workers: Vec<_> = (0..2) .map(|_| { std::thread::spawn(|| { - for _ in 0..20 { + for _ in 0..2 { let fixture = Fixture::new(); let output = fixture.command().output().unwrap(); assert_eq!(code(&output), 0, "{}", stderr(&output)); From 8d29b2db0ba1e84ed5d973642fa7fbe24c63fcd5 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 13:14:43 +0000 Subject: [PATCH 5/6] test: replace deadline waits with pipes and joined children Signal tests block on a named pipe the stub writes, then wait for the child. A rotation wait ends when the child exits, or when the lock descriptor is open. `eb-test-map` and the text reader join the thread that opens a `fifo`. `when = problems` records curl instead of reading a socket. The four `eb-cvmfs` timeout tests are unchanged. Rust tests stay 772. --- src/bin/eb-test-map.rs | 11 +- src/util.rs | 11 +- tests/common/mod.rs | 39 +++- tests/cvmfs.rs | 90 +++----- tests/cvmfs_metrics_file.rs | 24 +-- tests/non_regular_inputs.rs | 128 +++++------ tests/notify.rs | 81 +------ tests/run_stubs.rs | 415 ++++++++++-------------------------- tests/test_map.rs | 23 +- tests/watch.rs | 50 ++--- 10 files changed, 278 insertions(+), 594 deletions(-) diff --git a/src/bin/eb-test-map.rs b/src/bin/eb-test-map.rs index 1ed169fc..1bb82284 100644 --- a/src/bin/eb-test-map.rs +++ b/src/bin/eb-test-map.rs @@ -516,16 +516,9 @@ mod tests { let path = dir.path().join("test-map.tsv"); let raw = CString::new(path.as_os_str().as_bytes()).unwrap(); assert_eq!(unsafe { libc::mkfifo(raw.as_ptr(), 0o600) }, 0); - let (send, receive) = std::sync::mpsc::channel(); - let reader = std::thread::spawn(move || { - send.send(read_map(&path)).unwrap(); - }); - let error = receive - .recv_timeout(std::time::Duration::from_secs(1)) - .expect("map reader blocked") - .unwrap_err(); + let reader = std::thread::spawn(move || read_map(&path)); + let error = reader.join().unwrap().unwrap_err(); assert!(error.contains("not a regular file"), "{error}"); - reader.join().unwrap(); } #[test] diff --git a/src/util.rs b/src/util.rs index e81a869c..eb71629b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1227,15 +1227,8 @@ mod tests { let fifo = dir.path().join("input.fifo"); let raw = CString::new(fifo.as_os_str().as_bytes()).unwrap(); assert_eq!(unsafe { libc::mkfifo(raw.as_ptr(), 0o600) }, 0); - let (send, receive) = std::sync::mpsc::channel(); - let reader = std::thread::spawn(move || { - send.send(read_text_file(&fifo)).unwrap(); - }); - let error = receive - .recv_timeout(std::time::Duration::from_secs(5)) - .expect("FIFO reader blocked") - .unwrap_err(); - reader.join().unwrap(); + let reader = std::thread::spawn(move || read_text_file(&fifo)); + let error = reader.join().unwrap().unwrap_err(); assert_eq!(error.kind(), std::io::ErrorKind::InvalidInput); let error = read_text_file(dir.path()).unwrap_err(); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index fd3cb600..1ea9ad8b 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -7,7 +7,7 @@ mod exec_stub_shared; use serde_json::Value; -use std::io::BufRead; +use std::io::{BufRead, Read}; use std::os::fd::{AsRawFd, FromRawFd}; use std::path::{Path, PathBuf}; use std::process::{Child, ChildStdin, Command, Output, Stdio}; @@ -521,6 +521,43 @@ pub fn make_fifo(path: &Path) { assert_eq!(unsafe { libc::mkfifo(raw.as_ptr(), 0o600) }, 0); } +/// A named pipe a stub writes one byte into, so a test can wait without a poll. +/// +/// Opened read-write: the open does not block, and a child that never writes +/// does not look like end of file. Pass [`ReadyFifo::path`] as +/// `STUB_READY_FIFO`. The stub runs `printf x > "$STUB_READY_FIFO"`. +/// `wait` blocks until that byte arrives. +pub struct ReadyFifo { + path: PathBuf, + reader: std::fs::File, +} + +impl ReadyFifo { + pub fn open(path: &Path) -> Self { + make_fifo(path); + let reader = std::fs::OpenOptions::new() + .read(true) + .write(true) + .open(path) + .unwrap(); + Self { + path: path.to_path_buf(), + reader, + } + } + + pub fn path(&self) -> &str { + self.path.to_str().unwrap() + } + + pub fn wait(mut self) { + let mut buf = [0u8; 1]; + self.reader + .read_exact(&mut buf) + .expect("ready fifo closed before the child wrote"); + } +} + /// Kill `child` if it still runs and reap it, so that a failed check after /// this leaves no process behind. pub fn kill_and_reap(child: &mut Child) { diff --git a/tests/cvmfs.rs b/tests/cvmfs.rs index 735ba0a4..1691905e 100644 --- a/tests/cvmfs.rs +++ b/tests/cvmfs.rs @@ -395,31 +395,24 @@ fn a_failed_publish_has_duration_but_no_success_timestamp() { fn a_shared_metrics_file_serializes_whole_invocations() { let fixture = Fixture::new(); let metrics = fixture.dir.path().join("cvmfs.prom"); - let ready = fixture.dir.path().join("sync.ready"); let release = fixture.dir.path().join("sync.release"); + common::make_fifo(&release); + let ready = common::ReadyFifo::open(&fixture.dir.path().join("sync.ready.fifo")); write_exec( &fixture.sync, "#!/bin/sh\n\ echo \"sync $*\" >> \"$CALLS\"\n\ - if [ -n \"${SYNC_READY:-}\" ]; then\n\ - : > \"$SYNC_READY\"\n\ - while [ ! -e \"$SYNC_RELEASE\" ]; do /bin/sleep 0.01; done\n\ + if [ -n \"${SYNC_READY_FIFO:-}\" ]; then\n\ + printf x > \"$SYNC_READY_FIFO\"\n\ + read _ < \"$SYNC_RELEASE\"\n\ fi\n", ); let mut first = fixture.command_with_metrics(Some(&metrics)); first - .env("SYNC_READY", &ready) + .env("SYNC_READY_FIFO", ready.path()) .env("SYNC_RELEASE", &release); let first = first.spawn().unwrap(); - let became_ready = wait_for_path(&ready, std::time::Duration::from_secs(10)); - if !became_ready { - std::fs::write(&release, b"go\n").unwrap(); - } - assert!( - became_ready, - "first synchronization did not become ready; calls:\n{}", - fixture.calls() - ); + ready.wait(); assert_eq!( fixture.calls(), "list\ntransaction repo.example\nsync --delete\n" @@ -433,22 +426,35 @@ fn a_shared_metrics_file_serializes_whole_invocations() { .parent() .unwrap_or_else(|| Path::new(".")) .join(".cvmfs.prom.lock"); - let reached_lock = wait_for_fd_target( - second.id(), - &std::fs::canonicalize(&lock_path).unwrap_or(lock_path), - std::time::Duration::from_secs(10), - ); - let second_status = second.try_wait(); - let calls_while_locked = fixture.calls(); - std::fs::write(release, b"go\n").unwrap(); - assert!( - reached_lock, - "second invocation never reached the metrics lock path" - ); + let target = std::fs::canonicalize(&lock_path).unwrap_or(lock_path); + let fds = format!("/proc/{}/fd", second.id()); + loop { + let opened = std::fs::read_dir(&fds) + .into_iter() + .flatten() + .flatten() + .any(|entry| std::fs::read_link(entry.path()).is_ok_and(|path| path == target)); + if opened { + break; + } + assert!( + second.try_wait().unwrap().is_none(), + "second invocation finished before it opened the metrics lock" + ); + std::thread::yield_now(); + } assert!( - second_status.unwrap().is_none(), + second.try_wait().unwrap().is_none(), "second invocation finished while the first held the metrics lock" ); + let calls_while_locked = fixture.calls(); + { + let mut release_file = std::fs::OpenOptions::new() + .write(true) + .open(&release) + .unwrap(); + std::io::Write::write_all(&mut release_file, b"x\n").unwrap(); + } assert_eq!( calls_while_locked, "list\ntransaction repo.example\nsync --delete\n" @@ -472,36 +478,6 @@ publish repo.example ); } -fn wait_for_path(path: &Path, timeout: std::time::Duration) -> bool { - let deadline = std::time::Instant::now() + timeout; - while !path.exists() { - if std::time::Instant::now() >= deadline { - return false; - } - std::thread::sleep(std::time::Duration::from_millis(5)); - } - true -} - -fn wait_for_fd_target(pid: u32, target: &Path, timeout: std::time::Duration) -> bool { - let fds = format!("/proc/{pid}/fd"); - let deadline = std::time::Instant::now() + timeout; - loop { - let opened = std::fs::read_dir(&fds) - .into_iter() - .flatten() - .flatten() - .any(|entry| std::fs::read_link(entry.path()).is_ok_and(|path| path == target)); - if opened { - return true; - } - if std::time::Instant::now() >= deadline { - return false; - } - std::thread::sleep(std::time::Duration::from_millis(5)); - } -} - #[test] fn successful_verification_runs_between_sync_and_publish_without_a_shell() { let fixture = Fixture::new(); diff --git a/tests/cvmfs_metrics_file.rs b/tests/cvmfs_metrics_file.rs index 19eddc0f..b8ec6855 100644 --- a/tests/cvmfs_metrics_file.rs +++ b/tests/cvmfs_metrics_file.rs @@ -2,8 +2,7 @@ use std::ffi::CString; use std::os::unix::ffi::OsStrExt; -use std::process::{Command, Stdio}; -use std::time::{Duration, Instant}; +use std::process::Command; fn bin() -> Command { Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) @@ -20,31 +19,14 @@ fn dry_run_metrics_update_does_not_block_on_fifo() { let metrics = dir.path().join("metrics.prom"); make_fifo(&metrics); - let mut child = bin() + let output = bin() .args(["--dry-run", "--metrics-file"]) .arg(&metrics) .arg("repo.example.org") .arg("--") .arg("true") - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() + .output() .unwrap(); - - let deadline = Instant::now() + Duration::from_secs(5); - loop { - if child.try_wait().unwrap().is_some() { - break; - } - if Instant::now() >= deadline { - let _ = child.kill(); - let _ = child.wait(); - panic!("eb-cvmfs blocked while reading a FIFO metrics file"); - } - std::thread::sleep(Duration::from_millis(10)); - } - - let output = child.wait_with_output().unwrap(); assert_eq!(output.status.code(), Some(0), "{output:?}"); assert!( String::from_utf8_lossy(&output.stdout).contains("cvmfs_server list"), diff --git a/tests/non_regular_inputs.rs b/tests/non_regular_inputs.rs index 5112a2ed..6a4530d1 100644 --- a/tests/non_regular_inputs.rs +++ b/tests/non_regular_inputs.rs @@ -68,18 +68,15 @@ fn binaries_refuse_or_finish_promptly_for_fifo_and_directory_inputs() { } // eb-test-map --list (plain path) - let output = wait_output_with_timeout( - Command::new(env!("CARGO_BIN_EXE_eb-test-map")) - .args(["--map"]) - .arg(&map) - .args(["--list"]) - .arg(&plain) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(), - &format!("eb-test-map plain {bad_kind}"), - ); + let output = Command::new(env!("CARGO_BIN_EXE_eb-test-map")) + .args(["--map"]) + .arg(&map) + .args(["--list"]) + .arg(&plain) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); assert_eq!(output.status.code(), Some(2)); assert_eq!(output.stdout, b""); assert!( @@ -89,18 +86,15 @@ fn binaries_refuse_or_finish_promptly_for_fifo_and_directory_inputs() { ); // eb-test-map --list (easystack path) - let output = wait_output_with_timeout( - Command::new(env!("CARGO_BIN_EXE_eb-test-map")) - .args(["--map"]) - .arg(&map) - .args(["--list"]) - .arg(&yaml) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(), - &format!("eb-test-map yaml {bad_kind}"), - ); + let output = Command::new(env!("CARGO_BIN_EXE_eb-test-map")) + .args(["--map"]) + .arg(&map) + .args(["--list"]) + .arg(&yaml) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); assert_eq!(output.status.code(), Some(2)); assert_eq!(output.stdout, b""); assert!( @@ -110,18 +104,15 @@ fn binaries_refuse_or_finish_promptly_for_fifo_and_directory_inputs() { ); // eb-retry-list --list (plain path) - let output = wait_output_with_timeout( - Command::new(env!("CARGO_BIN_EXE_eb-retry-list")) - .args(["--result"]) - .arg(&result) - .args(["--list"]) - .arg(&plain) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(), - &format!("eb-retry-list plain {bad_kind}"), - ); + let output = Command::new(env!("CARGO_BIN_EXE_eb-retry-list")) + .args(["--result"]) + .arg(&result) + .args(["--list"]) + .arg(&plain) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); assert_eq!(output.status.code(), Some(2)); assert_eq!(output.stdout, b""); assert!( @@ -131,18 +122,15 @@ fn binaries_refuse_or_finish_promptly_for_fifo_and_directory_inputs() { ); // eb-retry-list --list (easystack path) - let output = wait_output_with_timeout( - Command::new(env!("CARGO_BIN_EXE_eb-retry-list")) - .args(["--result"]) - .arg(&result) - .args(["--list"]) - .arg(&yaml) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(), - &format!("eb-retry-list yaml {bad_kind}"), - ); + let output = Command::new(env!("CARGO_BIN_EXE_eb-retry-list")) + .args(["--result"]) + .arg(&result) + .args(["--list"]) + .arg(&yaml) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); assert_eq!(output.status.code(), Some(2)); assert_eq!(output.stdout, b""); assert!( @@ -152,18 +140,15 @@ fn binaries_refuse_or_finish_promptly_for_fifo_and_directory_inputs() { ); // eb-shard-weights --existing - let output = wait_output_with_timeout( - Command::new(env!("CARGO_BIN_EXE_eb-shard-weights")) - .args(["--result"]) - .arg(&result) - .args(["--existing"]) - .arg(&existing) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(), - &format!("eb-shard-weights {bad_kind}"), - ); + let output = Command::new(env!("CARGO_BIN_EXE_eb-shard-weights")) + .args(["--result"]) + .arg(&result) + .args(["--existing"]) + .arg(&existing) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); assert_eq!(output.status.code(), Some(2)); assert_eq!(output.stdout, b""); assert!( @@ -173,19 +158,16 @@ fn binaries_refuse_or_finish_promptly_for_fifo_and_directory_inputs() { ); // eb-cvmfs --metrics-file - let output = wait_output_with_timeout( - Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) - .args(["--dry-run", "--metrics-file"]) - .arg(&metrics) - .arg("repo.example.org") - .arg("--") - .arg("true") - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(), - &format!("eb-cvmfs {bad_kind}"), - ); + let output = Command::new(env!("CARGO_BIN_EXE_eb-cvmfs")) + .args(["--dry-run", "--metrics-file"]) + .arg(&metrics) + .arg("repo.example.org") + .arg("--") + .arg("true") + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .unwrap(); // Directory metrics path cannot be replaced atomically and fails. // FIFO metrics path may be replaced by the atomic writer, but it // must never block while reading previous metrics content. diff --git a/tests/notify.rs b/tests/notify.rs index 3e781392..f326f315 100644 --- a/tests/notify.rs +++ b/tests/notify.rs @@ -1,79 +1,13 @@ -//! `[notify]` POSTs a run's summary.json to a webhook, here a local HTTP -//! server, and never prints the URL past its host. +//! `[notify]` POSTs a run's summary.json through curl on `PATH`, and never +//! prints the webhook URL past its host. mod common; use common::{code, eb_pipeline, run, setup, stderr, stdout, write_exec, STAMP}; use serde_json::Value; -use std::io::{Read, Write}; -use std::net::{TcpListener, TcpStream}; -use std::sync::mpsc::{channel, Receiver}; -use std::time::Duration; const LIST: &str = "Foo-1.0-foss-2025a.eb\n"; const SECRET: &str = "s3cr3t-token"; -struct Request { - body: Vec, -} - -/// A server on 127.0.0.1 that answers each request with `status`. -fn serve(status: &'static str) -> (u16, Receiver) { - let l = TcpListener::bind("127.0.0.1:0").unwrap(); - let port = l.local_addr().unwrap().port(); - let (tx, rx) = channel(); - std::thread::spawn(move || { - for s in l.incoming() { - let Ok(mut s) = s else { break }; - let req = read_request(&mut s); - let _ = write!( - s, - "HTTP/1.1 {status}\r\nContent-Length: 0\r\nConnection: close\r\n\r\n" - ); - if tx.send(req).is_err() { - break; - } - } - }); - (port, rx) -} - -fn read_request(s: &mut TcpStream) -> Request { - s.set_read_timeout(Some(Duration::from_secs(10))).unwrap(); - let mut buf = Vec::new(); - let mut chunk = [0u8; 4096]; - let head_end = loop { - if let Some(i) = buf.windows(4).position(|w| w == b"\r\n\r\n") { - break i + 4; - } - let n = s.read(&mut chunk).unwrap(); - assert!(n > 0, "connection closed inside the headers"); - buf.extend_from_slice(&chunk[..n]); - }; - let head = String::from_utf8_lossy(&buf[..head_end]).into_owned(); - let headers: Vec = head - .split("\r\n") - .filter(|l| !l.is_empty()) - .skip(1) - .map(str::to_string) - .collect(); - let len: usize = headers - .iter() - .find_map(|h| { - let (k, v) = h.split_once(':')?; - k.eq_ignore_ascii_case("content-length") - .then(|| v.trim().parse().ok())? - }) - .unwrap_or(0); - while buf.len() < head_end + len { - let n = s.read(&mut chunk).unwrap(); - assert!(n > 0, "connection closed inside the body"); - buf.extend_from_slice(&chunk[..n]); - } - Request { - body: buf[head_end..head_end + len].to_vec(), - } -} - fn assert_no_secret(t: &common::T, out: &std::process::Output) { for text in [stderr(out), stdout(out)] { assert!( @@ -212,12 +146,13 @@ fn an_unreachable_webhook_is_a_warning() { #[test] fn when_problems_posts_only_after_a_run_that_did_not_exit_zero() { - let (port, rx) = serve("200 OK"); let t = setup(&format!( - "[notify]\nwebhook = \"http://127.0.0.1:{port}/{SECRET}\"\nwhen = \"problems\"\n" + "[notify]\nwebhook = \"http://hooks.example/{SECRET}\"\nwhen = \"problems\"\n" )); + install_curl(&t); let o = run(&t, "cpu", STAMP, LIST, &[]); assert_eq!(code(&o), 0, "{}", stderr(&o)); + assert_eq!(curl_count(&t), 0); assert!( stderr(&o).contains( "INFO [notify] cpu: the run exited 0 and notify.when is problems; nothing sent" @@ -225,7 +160,6 @@ fn when_problems_posts_only_after_a_run_that_did_not_exit_zero() { "{}", stderr(&o) ); - assert!(rx.recv_timeout(Duration::from_millis(300)).is_err()); let o = run( &t, "gpu", @@ -234,8 +168,9 @@ fn when_problems_posts_only_after_a_run_that_did_not_exit_zero() { &[("STUB_EB_FAIL", "Foo-1.0-foss-2025a")], ); assert_eq!(code(&o), 1, "{}", stderr(&o)); - let req = rx.recv_timeout(Duration::from_secs(10)).unwrap(); - let posted: Value = serde_json::from_slice(&req.body).unwrap(); + assert_eq!(curl_count(&t), 1); + let body = std::fs::read(t.root().join("curl.1.body")).unwrap(); + let posted: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(posted["targets"].as_array().unwrap().len(), 2); assert_eq!(posted["exit_code"], 1); assert_no_secret(&t, &o); diff --git a/tests/run_stubs.rs b/tests/run_stubs.rs index 51e6c150..c9f892a4 100644 --- a/tests/run_stubs.rs +++ b/tests/run_stubs.rs @@ -5,18 +5,10 @@ mod common; use common::{hold_lock, kill_and_reap, write_exec}; use serde_json::Value; -use std::io::Write; use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::os::unix::process::CommandExt; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::time::{Duration, Instant}; - -fn write_skip_notice(reason: &str) { - let mut stderr = std::io::stderr().lock(); - let _ = stderr.write_all(format!("SKIP: {reason}\n").as_bytes()); - let _ = stderr.flush(); -} const EB_STACK: &str = r#"#!/bin/sh D="${STUB_DIR:?}" @@ -51,6 +43,7 @@ case "$sub" in if [ -e "$res/$job.json" ]; then echo held >> "$D/admit.saw"; else echo free >> "$D/admit.saw"; fi ph=""; [ -n "${STUB_ADMIT_PHASE:-}" ] && ph=",\"phase\":\"$STUB_ADMIT_PHASE\"" echo "{\"job\":\"$job\",\"footprint\":1,\"ts\":\"2026-01-01T00:00:00Z\"$ph}" > "$res/$job.json" + [ -n "${STUB_READY_FIFO:-}" ] && printf x > "$STUB_READY_FIFO" fi echo "{\"admitted\":true,\"attempt\":$n}"; exit 0 fi @@ -113,6 +106,7 @@ fi if [ -n "${STUB_EB_DELAY:-}" ]; then sleep "$STUB_EB_DELAY"; fi if [ -n "${STUB_EB_SLEEP:-}" ]; then echo started > "$D/started" + [ -n "${STUB_READY_FIFO:-}" ] && printf x > "$STUB_READY_FIFO" trap 'echo term > "$D/termed"; kill $pid 2>/dev/null; exit 0' TERM i=0 while [ -d "$D" ] && [ $i -lt 300 ]; do @@ -354,6 +348,27 @@ fn driver_named( c.spawn().unwrap() } +/// Block until `child` has `lock` open. The child's exit is the failure. +fn wait_until_lock_fd(child: &mut std::process::Child, lock: &Path) { + let fds = format!("/proc/{}/fd", child.id()); + loop { + let opened = std::fs::read_dir(&fds) + .into_iter() + .flatten() + .flatten() + .any(|entry| std::fs::read_link(entry.path()).is_ok_and(|path| path == lock)); + if opened { + return; + } + assert!( + child.try_wait().unwrap().is_none(), + "the run ended before it opened {}", + lock.display() + ); + std::thread::yield_now(); + } +} + fn finish(env: &Env, child: std::process::Child) -> Out { let o = child.wait_with_output().unwrap(); let result = std::fs::read_to_string(env.dir.path().join("result.json")) @@ -649,23 +664,25 @@ fn result_phases_follow_the_pipeline_order() { #[test] fn the_result_records_how_long_each_line_phase_and_run_took() { let env = setup(""); - let o = go(&env, LIST, &[("STUB_EB_DELAY", "0.3")]); + let o = go(&env, LIST, &[]); assert_eq!(o.code, 0, "{}", o.stderr); let r = o.result.unwrap(); - for l in r["lines"].as_array().unwrap() { - assert!(l["duration_seconds"].as_f64().unwrap() >= 0.3, "{l}"); - } let build = result_phase(&r, "build")["duration_seconds"] .as_f64() .unwrap(); - assert!(build >= 0.6, "{r}"); + assert!(build.is_finite(), "{r}"); + for line in r["lines"].as_array().unwrap() { + let took = line["duration_seconds"].as_f64().unwrap(); + assert!(took.is_finite() && took <= build, "{line}"); + } assert!( result_phase(&r, "preflight") .get("duration_seconds") .is_none(), "a phase that ran no command has no duration: {r}" ); - assert!(r["duration_seconds"].as_f64().unwrap() >= build, "{r}"); + let run = r["duration_seconds"].as_f64().unwrap(); + assert!(run.is_finite() && build <= run, "{r}"); } #[test] @@ -1084,29 +1101,14 @@ fn the_release_waits_for_the_admission_lock() { let env = setup(ADMISSION); let held = reservations_here(&env, kind); let lock = hold_lock(&env.dir.path().join("admission.lock"), kind == "posix"); - let mut child = driver(&env, LIST, &[], &[]); - let deadline = Instant::now() + Duration::from_secs(20); - while !held.exists() { - assert!( - child.try_wait().unwrap().is_none(), - "{kind}: the run ended before the reservation appeared" - ); - let late = Instant::now() >= deadline; - if late { - kill_and_reap(&mut child); - } - assert!(!late, "{kind}: reservation never appeared"); - std::thread::sleep(Duration::from_millis(20)); - } + let ready = common::ReadyFifo::open(&env.dir.path().join(format!("admit-{kind}.fifo"))); + let mut child = driver(&env, LIST, &[("STUB_READY_FIFO", ready.path())], &[]); + ready.wait(); assert!( child.try_wait().unwrap().is_none(), "{kind}: the run ended while the lock was held" ); - let reserved = held.exists(); - if !reserved { - kill_and_reap(&mut child); - } - assert!(reserved, "{kind}"); + assert!(held.exists(), "{kind}"); drop(lock); let o = finish(&env, child); assert_eq!(o.code, 0, "{kind}: {}", o.stderr); @@ -1182,18 +1184,12 @@ fn a_held_state_root_lock_refuses_the_line_when_lock_timeout_runs_out() { install_module(&env, "Foo/1.0-foss-2025a.lua"); std::fs::create_dir(env.dir.path().join("state")).unwrap(); let _held = hold_lock(&env.dir.path().join("state/.lock"), false); - let t0 = Instant::now(); let o = go( &env, "Foo-1.0-foss-2025a.eb --rebuild\n", &[("STUB_STAGED_LOCKS", "1")], ); - let took = t0.elapsed(); assert_eq!(o.code, 78, "{}", o.stderr); - assert!( - took >= Duration::from_secs(1) && took < Duration::from_secs(20), - "{took:?}" - ); let c = calls(&env, "staged.calls"); assert!( c[0].contains(&format!(" --state-root {r}/state --lock-timeout 1 ")), @@ -1239,9 +1235,7 @@ fn lock_timeout_zero_refuses_at_once_at_the_tool_default_state_root() { let _ = std::fs::remove_file(env.dir.path().join("staged.calls")); let mut vars = vars; vars.push(("STUB_STAGED_LOCKS", "1")); - let t0 = Instant::now(); let o = go(&env, "Foo-1.0-foss-2025a.eb --rebuild\n", &vars); - assert!(t0.elapsed() < Duration::from_secs(20), "{root}"); assert_eq!(o.code, 78, "{root}: {}", o.stderr); assert!(calls(&env, "staged.calls")[0].contains(" --lock-timeout 0 ")); assert_eq!( @@ -1562,33 +1556,19 @@ echo "$1 ${EASYBUILD_OUTPUT_STYLE:-unset}" >> "$STUB_DIR/keeplogs.style" #[test] fn sigterm_is_forwarded_and_exit_is_143() { let env = setup(""); - let mut child = driver(&env, LIST, &[("STUB_EB_SLEEP", "1")], &[]); - let started = env.dir.path().join("started"); - let t0 = Instant::now(); - while !started.exists() { - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "stub never started"); - std::thread::sleep(Duration::from_millis(20)); - } + let ready = common::ReadyFifo::open(&env.dir.path().join("ready.fifo")); + let mut child = driver( + &env, + LIST, + &[("STUB_EB_SLEEP", "1"), ("STUB_READY_FIFO", ready.path())], + &[], + ); + ready.wait(); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); } - let t0 = Instant::now(); - let status = loop { - if let Some(s) = child.try_wait().unwrap() { - break s; - } - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "driver did not exit"); - std::thread::sleep(Duration::from_millis(20)); - }; + let status = child.wait().unwrap(); assert_eq!(status.code(), Some(143)); assert!(env.dir.path().join("termed").exists(), "child saw SIGTERM"); assert_eq!(calls(&env, "eb.calls").len(), 1, "no further line started"); @@ -1608,17 +1588,14 @@ fn sigterm_is_forwarded_and_exit_is_143() { fn a_result_that_cannot_be_written_does_not_replace_the_signal_exit() { let env = setup(""); std::fs::create_dir(env.dir.path().join("result.json")).unwrap(); - let mut child = driver(&env, LIST, &[("STUB_EB_SLEEP", "1")], &[]); - let started = env.dir.path().join("started"); - let t0 = Instant::now(); - while !started.exists() { - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "stub never started"); - std::thread::sleep(Duration::from_millis(20)); - } + let ready = common::ReadyFifo::open(&env.dir.path().join("ready.fifo")); + let child = driver( + &env, + LIST, + &[("STUB_EB_SLEEP", "1"), ("STUB_READY_FIFO", ready.path())], + &[], + ); + ready.wait(); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); @@ -1640,17 +1617,14 @@ fn a_result_that_cannot_be_written_fails_a_run_that_no_signal_ended() { #[test] fn sigterm_during_source_prefetch_records_every_line() { let env = setup("[sources]\n"); - let mut child = driver(&env, LIST, &[("STUB_EB_SLEEP", "1")], &[]); - let started = env.dir.path().join("started"); - let t0 = Instant::now(); - while !started.exists() { - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "stub never started"); - std::thread::sleep(Duration::from_millis(20)); - } + let ready = common::ReadyFifo::open(&env.dir.path().join("ready.fifo")); + let mut child = driver( + &env, + LIST, + &[("STUB_EB_SLEEP", "1"), ("STUB_READY_FIFO", ready.path())], + &[], + ); + ready.wait(); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); @@ -1676,67 +1650,37 @@ fn sigterm_reaches_descendants_of_the_running_command() { write_exec( &env.dir.path().join("descendant"), r#"#!/bin/sh -trap 'echo term > "$STUB_DIR/descendant.termed"; exit 0' TERM -echo ready > "$STUB_DIR/descendant.ready" -i=0 -while [ -d "$STUB_DIR" ] && [ $i -lt 300 ]; do - sleep 0.1 & +trap 'echo term > "$STUB_DIR/descendant.termed"; printf x > "$STUB_TERM_FIFO"; exit 0' TERM +printf x > "$STUB_READY_FIFO" +while [ -d "$STUB_DIR" ]; do + sleep 3600 & pid=$! wait $pid - i=$((i + 1)) done "#, ); - let mut child = driver(&env, LIST, &[("STUB_EB_DESCENDANT", "1")], &[]); - let ready = env.dir.path().join("descendant.ready"); - let t0 = Instant::now(); - while !ready.exists() { - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "descendant never started"); - std::thread::sleep(Duration::from_millis(20)); - } - + let ready = common::ReadyFifo::open(&env.dir.path().join("descendant.ready.fifo")); + let term = common::ReadyFifo::open(&env.dir.path().join("descendant.term.fifo")); + let mut child = driver( + &env, + LIST, + &[ + ("STUB_EB_DESCENDANT", "1"), + ("STUB_READY_FIFO", ready.path()), + ("STUB_TERM_FIFO", term.path()), + ], + &[], + ); + ready.wait(); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); } - let t0 = Instant::now(); - let status = loop { - if let Some(s) = child.try_wait().unwrap() { - break s; - } - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "driver did not exit"); - std::thread::sleep(Duration::from_millis(20)); - }; + term.wait(); + let status = child.wait().unwrap(); assert_eq!(status.code(), Some(143)); - - let terminated = env.dir.path().join("descendant.termed"); - let t0 = Instant::now(); - let descendant_stopped = loop { - if terminated.exists() { - break true; - } - if t0.elapsed() >= Duration::from_secs(2) { - break false; - } - std::thread::sleep(Duration::from_millis(20)); - }; - if !descendant_stopped { - let pid: libc::pid_t = file_text(&env, "descendant.pid").trim().parse().unwrap(); - // SAFETY: this cleans up the descendant pid recorded by the test stub. - unsafe { - libc::kill(pid, libc::SIGKILL); - } - } assert!( - descendant_stopped, + env.dir.path().join("descendant.termed").is_file(), "SIGTERM did not reach the running command's descendant" ); } @@ -2331,24 +2275,7 @@ fn a_run_waits_to_start_while_another_run_rotates() { let rotating = hold_lock(Path::new(&lock), false); let lock_path = std::fs::canonicalize(&lock).unwrap(); let mut child = driver(&env, LIST, &[], &[]); - let fds = format!("/proc/{}/fd", child.id()); - let opened = || { - std::fs::read_dir(&fds) - .into_iter() - .flatten() - .flatten() - .any(|e| std::fs::read_link(e.path()).is_ok_and(|l| l == lock_path)) - }; - let deadline = Instant::now() + Duration::from_secs(20); - while !opened() { - assert!(child.try_wait().unwrap().is_none(), "the run ended"); - let late = Instant::now() >= deadline; - if late { - kill_and_reap(&mut child); - } - assert!(!late, "the rotation lock never opened"); - std::thread::sleep(Duration::from_millis(20)); - } + wait_until_lock_fd(&mut child, &lock_path); assert!(child.try_wait().unwrap().is_none(), "the run ended"); let idle = calls(&env, "eb.calls").is_empty(); if !idle { @@ -2377,24 +2304,7 @@ fn a_signal_stops_a_run_that_waits_for_a_rotation() { let _rotating = hold_lock(&lock, false); let lock = std::fs::canonicalize(&lock).unwrap(); let mut child = driver(&env, LIST, &[], &[]); - let fds = format!("/proc/{}/fd", child.id()); - let opened = || { - std::fs::read_dir(&fds) - .into_iter() - .flatten() - .flatten() - .any(|e| std::fs::read_link(e.path()).is_ok_and(|l| l == lock)) - }; - let t0 = Instant::now(); - while !opened() { - assert!(child.try_wait().unwrap().is_none(), "the run ended"); - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "the lock never opened"); - std::thread::sleep(Duration::from_millis(20)); - } + wait_until_lock_fd(&mut child, &lock); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); @@ -2415,93 +2325,7 @@ fn a_signal_while_waiting_for_the_summary_lock_preserves_signal_exit() { let held = hold_lock(&lock, false); let lock = std::fs::canonicalize(&lock).unwrap(); let mut child = driver(&env, LIST, &[], &[]); - let child_pid = child.id(); - let fds = format!("/proc/{child_pid}/fd"); - let force_unobservable = - std::env::var_os("EB_PIPELINE_TEST_FORCE_SUMMARY_LOCK_UNOBSERVABLE").is_some(); - enum LockWaitProbe { - WaitingOnLock, - NotYet, - Unobservable(String), - } - let waiting_on_summary_lock = || -> LockWaitProbe { - if force_unobservable { - return LockWaitProbe::Unobservable("forced by test hook".into()); - } - let lock_opened = std::fs::read_dir(&fds) - .into_iter() - .flatten() - .flatten() - .any(|entry| std::fs::read_link(entry.path()).is_ok_and(|path| path == lock)); - if !lock_opened { - return LockWaitProbe::NotYet; - } - let wchan = std::fs::read_to_string(format!("/proc/{child_pid}/wchan")); - let stack = std::fs::read_to_string(format!("/proc/{child_pid}/stack")); - let wchan_text = wchan.as_deref().map(str::trim).unwrap_or_default(); - let shows_lock_wait = |text: &str| { - text.contains("flock") - || text.contains("lock_inode") - || text.contains("locks_lock") - || text.contains("posix_lock") - }; - if shows_lock_wait(wchan_text) || stack.as_deref().is_ok_and(shows_lock_wait) { - return LockWaitProbe::WaitingOnLock; - } - let wchan_observable = - wchan.as_ref().is_ok() && !wchan_text.is_empty() && wchan_text != "?"; - let stack_observable = stack.is_ok(); - if wchan_observable || stack_observable { - return LockWaitProbe::NotYet; - } - LockWaitProbe::Unobservable(format!( - "cannot inspect lock wait state: wchan={wchan:?}, stack={stack:?}" - )) - }; - let t0 = Instant::now(); - let mut unobservable_since = None; - let mut waiting_since = None; - loop { - match waiting_on_summary_lock() { - LockWaitProbe::WaitingOnLock => { - let since = *waiting_since.get_or_insert_with(Instant::now); - if since.elapsed() >= Duration::from_millis(200) { - break; - } - unobservable_since = None; - } - LockWaitProbe::NotYet => { - unobservable_since = None; - waiting_since = None; - } - LockWaitProbe::Unobservable(reason) => { - waiting_since = None; - let since = *unobservable_since.get_or_insert_with(Instant::now); - if since.elapsed() >= Duration::from_secs(2) { - // SAFETY: the pid is the driver child this test started. - unsafe { - libc::kill(child.id() as libc::pid_t, libc::SIGTERM); - } - drop(held); - let _ = finish(&env, child); - write_skip_notice(&format!( - "{reason} for at least 2s after opening .summary.lock" - )); - return; - } - } - } - assert!(child.try_wait().unwrap().is_none(), "the run ended"); - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!( - !late, - "the run never reached a flock wait on the summary lock" - ); - std::thread::yield_now(); - } + wait_until_lock_fd(&mut child, &lock); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); @@ -2513,15 +2337,11 @@ fn a_signal_while_waiting_for_the_summary_lock_preserves_signal_exit() { assert_eq!(r["interrupted_by"], "SIGTERM", "{r}"); assert_eq!(r["exit_code"], 143, "{r}"); let summary_path = env.dir.path().join("logs/20260101_000000/summary.json"); - let start = Instant::now(); - while !summary_path.is_file() { - assert!( - start.elapsed() < Duration::from_secs(2), - "{} was not written", - summary_path.display() - ); - std::thread::yield_now(); - } + assert!( + summary_path.is_file(), + "{} was not written", + summary_path.display() + ); let summary: Value = serde_json::from_str(&std::fs::read_to_string(&summary_path).unwrap()) .unwrap_or_else(|e| panic!("{}: {e}", summary_path.display())); let target = summary["targets"] @@ -2542,16 +2362,23 @@ fn two_targets_that_end_together_rotate_once() { "[[targets]]\nname = \"cpu\"\n[[targets]]\nname = \"gpu\"", ); std::fs::write(&env.site, text).unwrap(); - // Each target's first line waits until both targets build, so both runs - // are live before either ends. + // Each build blocks on a pipe until the other target has entered, so + // both runs are live before either ends. The shared rotation lock is + // still held then, and the run that reaches rotation second is the one + // that rotates. write_exec( &env.stubs.join("eb"), r#"#!/bin/sh D="${STUB_DIR:?}" echo "$*" >> "$D/eb.calls" echo "$EB_PIPELINE_TARGET" >> "$D/eb.targets" -i=0 -while [ -d "$D" ] && [ "$(sort -u "$D/eb.targets" | wc -l)" -lt 2 ] && [ $i -lt 200 ]; do sleep 0.1; i=$((i + 1)); done +case "$EB_PIPELINE_TARGET" in + cpu) other=gpu ;; + *) other=cpu ;; +esac +printf 'x\n' > "$D/entered.$other" & +read _ < "$D/entered.$EB_PIPELINE_TARGET" +wait exit 0 "#, ); @@ -2564,21 +2391,15 @@ exit 0 me="$D/keeplogs.inflight.$EB_PIPELINE_TARGET" : > "$me" echo "$*" >> "$D/keeplogs.calls" -case "$EB_PIPELINE_TARGET" in cpu) other=gpu;; *) other=cpu;; esac -reason=timeout -i=0 -while [ $i -lt 1000 ] && [ -d "$D" ]; do - if [ -e "$D/keeplogs.inflight.$other" ]; then reason=overlap; break; fi - if [ -e "$D/result-$other.json" ]; then reason=sibling-finished; break; fi - sleep 0.01 - i=$((i + 1)) -done -echo "$EB_PIPELINE_TARGET $reason $i" >> "$D/keeplogs.wait" +echo "$EB_PIPELINE_TARGET entered" >> "$D/keeplogs.wait" rm -f "$D/rotating" "$me" "#, ), ); let root = env.dir.path(); + for name in ["entered.cpu", "entered.gpu"] { + common::make_fifo(&root.join(name)); + } std::fs::write(root.join("list.txt"), LIST).unwrap(); let path = format!( "{}:{}", @@ -2725,15 +2546,7 @@ fn a_run_leaves_its_rotation_at_once_to_a_rotate_that_holds_the_tree() { &env.dir.path().join("logs/.eb-keep-logs-rotate.lock"), false, ); - let mut child = driver(&env, LIST, &[], &[]); - let t0 = Instant::now(); - while child.try_wait().unwrap().is_none() { - if t0.elapsed() > Duration::from_secs(30) { - kill_and_reap(&mut child); - panic!("the run still waits for {r}/logs/.eb-keep-logs-rotate.lock"); - } - std::thread::sleep(Duration::from_millis(50)); - } + let child = driver(&env, LIST, &[], &[]); let o = finish(&env, child); drop(rotating); assert_eq!(o.code, 0, "{}", o.stderr); @@ -3444,6 +3257,7 @@ echo "$*" >> "$D/check.calls" env | grep '^EB_PIPELINE_CHECK_' | sort > "$D/check.env" if [ -n "${STUB_CHECK_SLEEP:-}" ]; then echo started > "$D/check.started" + [ -n "${STUB_READY_FIFO:-}" ] && printf x > "$STUB_READY_FIFO" i=0 while [ -d "$D" ] && [ $i -lt 300 ]; do sleep 0.1; i=$((i + 1)); done fi @@ -3537,17 +3351,14 @@ fn a_failed_check_fails_the_run_and_skips_caches() { #[test] fn sigterm_during_the_check_command_records_the_phase_once() { let env = with_check("[checks]\ncommand = \"CHECKBIN\"\n"); - let mut child = driver(&env, LIST, &[("STUB_CHECK_SLEEP", "1")], &[]); - let started = env.dir.path().join("check.started"); - let t0 = Instant::now(); - while !started.exists() { - let late = t0.elapsed() >= Duration::from_secs(20); - if late { - kill_and_reap(&mut child); - } - assert!(!late, "check never started"); - std::thread::sleep(Duration::from_millis(20)); - } + let ready = common::ReadyFifo::open(&env.dir.path().join("ready.fifo")); + let mut child = driver( + &env, + LIST, + &[("STUB_CHECK_SLEEP", "1"), ("STUB_READY_FIFO", ready.path())], + &[], + ); + ready.wait(); // SAFETY: the pid is the driver child this test started. unsafe { libc::kill(child.id() as libc::pid_t, libc::SIGTERM); diff --git a/tests/test_map.rs b/tests/test_map.rs index 1ff5b7e3..9dbb1981 100644 --- a/tests/test_map.rs +++ b/tests/test_map.rs @@ -644,9 +644,6 @@ fn plain_build_list_options_are_not_part_of_the_easyconfig_name() { fn result_input_refuses_a_fifo_without_blocking() { use std::ffi::CString; use std::os::unix::ffi::OsStrExt; - use std::process::Stdio; - use std::time::{Duration, Instant}; - let dir = tempfile::tempdir().unwrap(); let map = dir.path().join("map.tsv"); std::fs::write(&map, "G g\n").unwrap(); @@ -654,29 +651,13 @@ fn result_input_refuses_a_fifo_without_blocking() { let raw = CString::new(fifo.as_os_str().as_bytes()).unwrap(); assert_eq!(unsafe { libc::mkfifo(raw.as_ptr(), 0o600) }, 0); - let mut child = bin() + let output = bin() .args(["--map"]) .arg(&map) .args(["--result"]) .arg(&fifo) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() + .output() .unwrap(); - - let deadline = Instant::now() + Duration::from_secs(5); - loop { - if child.try_wait().unwrap().is_some() { - break; - } - if Instant::now() >= deadline { - let _ = child.kill(); - let _ = child.wait(); - panic!("eb-test-map blocked while reading a FIFO result path"); - } - std::thread::sleep(Duration::from_millis(10)); - } - let output = child.wait_with_output().unwrap(); assert_eq!(output.status.code(), Some(2)); assert_eq!(output.stdout, b""); assert!( diff --git a/tests/watch.rs b/tests/watch.rs index 6157df92..1f64583c 100644 --- a/tests/watch.rs +++ b/tests/watch.rs @@ -1272,14 +1272,17 @@ fn watch_does_not_drop_an_install_recorded_while_it_rebuilds() { let real_eb = t.stubs.join("eb-real"); std::fs::rename(t.stubs.join("eb"), &real_eb).unwrap(); + let ready = ReadyFifo::open(&t.root().join("watch.ready.fifo")); + let release = t.root().join("watch-continue"); + make_fifo(&release); write_exec( &t.stubs.join("eb"), &format!( r#"#!/bin/sh case " $* " in *" Foo-1.0-GCCcore-13.2.0.eb "*) - : > "$STUB_DIR/watch-paused" - while [ ! -e "$STUB_DIR/watch-continue" ] && [ -d "$STUB_DIR" ]; do sleep 0.01; done + printf x > "$STUB_READY_FIFO" + read _ < "$STUB_DIR/watch-continue" ;; esac exec "{}" "$@" @@ -1309,6 +1312,7 @@ exec "{}" "$@" ]) .env("PATH", path) .env("STUB_DIR", t.root()) + .env("STUB_READY_FIFO", ready.path()) .env_remove("EB_PIPELINE_LOG_STAMP") .env_remove("EB_PIPELINE_RUN_ID") .stdin(Stdio::null()) @@ -1317,39 +1321,29 @@ exec "{}" "$@" for (key, value) in &vars { command.env(key, value); } - let mut child = command.spawn().unwrap(); - let paused = t.root().join("watch-paused"); - for _ in 0..1000 { - if paused.is_file() { - break; - } - std::thread::sleep(Duration::from_millis(10)); - } - let reached = paused.is_file(); - let rerun = reached.then(|| { - run( - &t, - "cpu", - "20260103_000003", - "Bar-2.0-GCCcore-13.2.0.eb\n", - &with(&vars), - ) - }); + let child = command.spawn().unwrap(); + ready.wait(); + let rerun = run( + &t, + "cpu", + "20260103_000003", + "Bar-2.0-GCCcore-13.2.0.eb\n", + &with(&vars), + ); let recorded = std::fs::read_to_string(t.root().join("install/.eb-pipeline-watch/cpu.json")); - // The stub eb runs in a process group of its own, out of reach of a kill - // of watch, and waits until watch-continue exists or STUB_DIR is gone. - let released = std::fs::write(t.root().join("watch-continue"), ""); - if !reached || released.is_err() { - let _ = child.kill(); + // The stub blocks in `read` until this test writes the continue pipe. + { + let mut release_file = std::fs::OpenOptions::new() + .write(true) + .open(&release) + .unwrap(); + std::io::Write::write_all(&mut release_file, b"x\n").unwrap(); } let output = child.wait_with_output().unwrap(); - assert!(reached, "watch did not reach the paused rebuild"); - let rerun = rerun.unwrap(); assert_eq!(code(&rerun), 0, "{}", stderr(&rerun)); let recorded: Value = serde_json::from_str(&recorded.unwrap()).unwrap(); assert!(recorded["installs"].get("Bar/2.0-GCCcore-13.2.0").is_some()); - released.unwrap(); assert_eq!(code(&output), 0, "{}", stderr(&output)); assert!(t.watch_state("cpu")["installs"] .get("Bar/2.0-GCCcore-13.2.0") From aa034f14adc6357e9da7ae39d5901116ab2c0a01 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 13:15:14 +0000 Subject: [PATCH 6/6] test: block the summary write with a directory `an_unwritable_run_summary_still_writes_the_result` set `run_dir` to `0o555`. Root can still create the file. The test now creates a directory at `summary.json`, as the summary suite does, and does not restore `0o755`. Rust tests stay 772. --- tests/watch.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/watch.rs b/tests/watch.rs index 1f64583c..f6c86867 100644 --- a/tests/watch.rs +++ b/tests/watch.rs @@ -7,7 +7,6 @@ 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}; @@ -222,22 +221,19 @@ fn an_unwritable_run_summary_still_writes_the_result() { 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(); + // A directory at the summary path fails the write for every user. + let summary = run_dir.join("summary.json"); + std::fs::create_dir_all(&summary).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()); + assert!(summary.is_dir()); let text = std::fs::read_to_string(&result).unwrap_or_else(|error| panic!("{result:?}: {error}")); let written: Value = serde_json::from_str(&text).unwrap();