From 89bbc09830ba9eca61748c54b904a34c1fcda480 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Thu, 3 Dec 2026 17:09:11 -0800 Subject: [PATCH 1/5] test(runner): add a per-row test timeout to runner rows --test-timeout-minutes, and the test_timeout_minutes column in the e2e-suites.yml rows, replace a nextest bundle's two-minute slow-timeout for one run, so rows can hold the long Kubernetes and GPU tests ported from e2e/rust. The default stays two minutes; prebuilt programs keep their own limit. Closes #5295 Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 7 +++- TESTING.md | 7 ++++ tests/runner/src/bundle.rs | 60 +++++++++++++++++++++++++++++--- tests/runner/src/execute.rs | 3 +- tests/runner/src/main.rs | 39 ++++++++++++++++++++- 5 files changed, 108 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index 3de3608656..d906098db5 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -91,7 +91,8 @@ jobs: # installer registers with the CLI: `openshell` for the packages, # `tmachine` for the k3s and binaries installers. A row without a # package runs every package in the workspace; each driver suite is a - # workspace of its own. + # workspace of its own. `test_threads` and `test_timeout_minutes` + # pass `--test-threads` and `--test-timeout-minutes` to the runner. rows='[ {"environment":"ubuntu-docker-rootful","installer":"deb","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04","test_threads":4}, {"environment":"ubuntu-docker-rootful","installer":"deb-external-docker-driver","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04","external_driver":true,"test_threads":4}, @@ -290,6 +291,7 @@ jobs: GATEWAY: ${{ matrix.gateway }} DISRUPTION: ${{ matrix.disruption }} TEST_THREADS: ${{ matrix.test_threads }} + TEST_TIMEOUT_MINUTES: ${{ matrix.test_timeout_minutes }} run: | # The tests this environment can't pass yet; the runner passes the # variable on to the guest. @@ -323,6 +325,9 @@ jobs: if [ -n "${TEST_THREADS}" ]; then selection+=(--test-threads "${TEST_THREADS}") fi + if [ -n "${TEST_TIMEOUT_MINUTES}" ]; then + selection+=(--test-timeout-minutes "${TEST_TIMEOUT_MINUTES}") + fi # A continuity row seeds state, applies the disruption, and verifies. if [ -n "${DISRUPTION}" ]; then selection+=(--disruption "${DISRUPTION}") diff --git a/TESTING.md b/TESTING.md index 5cf0592fd0..5d4fa62fa8 100644 --- a/TESTING.md +++ b/TESTING.md @@ -330,6 +330,13 @@ and `nextest.log` to the results directory. Branch E2E builds the runner builds the suite or uses `--bundle` or `--program`. The default is one. CI rows can opt in with `test_threads`. +The runner terminates a test after two minutes, or after 15 minutes for +`--program`. `--test-timeout-minutes N` raises the limit to N minutes (below +the run's 45-minute limit) for a built or `--bundle` run, and CI rows set it +with `test_timeout_minutes`. The limit applies to every test in the row, so a +row runs at its slowest test's limit: put slow tests in rows of their own. +Keep it above the test's own step timeouts, so those report first. + `openshell-test-runner build --family --out ` builds a family's test bundle for the guest without booting a VM, and `run --bundle ` runs it instead of building one. `--package` then selects the tests to run from the diff --git a/tests/runner/src/bundle.rs b/tests/runner/src/bundle.rs index 05a485a2aa..d0aad09a92 100644 --- a/tests/runner/src/bundle.rs +++ b/tests/runner/src/bundle.rs @@ -17,6 +17,7 @@ //! can run it instead: the bundle then holds that program alone, built once //! elsewhere for the guest target, and the runner builds nothing. +use std::num::NonZeroU64; use std::os::unix::fs::PermissionsExt; use std::path::{Path, PathBuf}; use std::process::Command; @@ -36,16 +37,23 @@ pub const READY_BINARY: &str = "testkit-ready"; /// instead of holding the lane until the job times out. const SLOW_PERIOD_SECS: u64 = 30; const SLOW_TERMINATE_AFTER: u64 = 4; +/// The slow period when a row sets its own per-test timeout in minutes. +const MINUTE_SECS: u64 = 60; /// How long a terminated test has between SIGTERM and SIGKILL. const GRACE_PERIOD_SECS: u64 = 10; -/// The nextest configuration written into a nextest bundle. -fn nextest_config() -> String { +/// The nextest configuration written into a nextest bundle. Each test is +/// terminated after `timeout_minutes`, or after two minutes without one. +fn nextest_config(timeout_minutes: Option) -> String { + let (period, terminate_after) = timeout_minutes + .map_or((SLOW_PERIOD_SECS, SLOW_TERMINATE_AFTER), |minutes| { + (MINUTE_SECS, minutes.get()) + }); format!( r#"# Written by the OpenShell test runner. [profile.openshell] fail-fast = false -slow-timeout = {{ period = "{SLOW_PERIOD_SECS}s", terminate-after = {SLOW_TERMINATE_AFTER}, grace-period = "{GRACE_PERIOD_SECS}s" }} +slow-timeout = {{ period = "{period}s", terminate-after = {terminate_after}, grace-period = "{GRACE_PERIOD_SECS}s" }} [profile.openshell.junit] path = "junit.xml" @@ -91,6 +99,18 @@ impl Bundle { pub const fn kind(&self) -> Kind { self.1 } + + /// Terminate each test of a nextest bundle after `minutes` instead of + /// two minutes. The bundle is the runner's own copy, so this changes only + /// this run. + pub fn set_test_timeout(&self, minutes: NonZeroU64) -> Result<()> { + ensure!( + self.1 == Kind::Nextest, + "a per-test timeout applies to nextest bundles, not to a prebuilt program" + ); + std::fs::write(self.path().join(CONFIG), nextest_config(Some(minutes))) + .context("write the bundle's nextest config") + } } /// A bundle holding `program`, a testkit program already built for the @@ -219,7 +239,7 @@ pub fn build(root: &Path, family: &str, packages: &[String], out: &Path) -> Resu run(&mut command).with_context(|| format!("build the {} test archive", workspace.display()))?; copy_manifests(&workspace, out)?; - std::fs::write(out.join(CONFIG), nextest_config())?; + std::fs::write(out.join(CONFIG), nextest_config(None))?; std::fs::copy(&ready, out.join(READY_BINARY)) .with_context(|| format!("copy {}", ready.display()))?; let manifest = Manifest { @@ -360,12 +380,42 @@ mod tests { #[test] fn nextest_profile_stops_a_hung_test_after_two_minutes() { - let config = nextest_config(); + let config = nextest_config(None); assert!(config.contains( r#"slow-timeout = { period = "30s", terminate-after = 4, grace-period = "10s" }"# )); } + #[test] + fn test_timeout_replaces_the_bundle_slow_timeout() { + let dir = tempfile::tempdir().unwrap(); + write_bundle(dir.path(), "features", &[]); + let bundle = prebuilt(dir.path(), "features", &[]).unwrap(); + bundle + .set_test_timeout(NonZeroU64::new(20).unwrap()) + .unwrap(); + let config = std::fs::read_to_string(bundle.path().join(CONFIG)).unwrap(); + assert!(config.contains( + r#"slow-timeout = { period = "60s", terminate-after = 20, grace-period = "10s" }"# + )); + assert!(config.contains(&format!("[profile.{PROFILE}.junit]\n"))); + // The prebuilt bundle itself is unchanged. + assert_eq!( + std::fs::read(dir.path().join(CONFIG)).unwrap(), + CONFIG.as_bytes() + ); + + let program_dir = tempfile::tempdir().unwrap(); + let path = program_dir.path().join("openshell-conformance"); + std::fs::write(&path, b"binary").unwrap(); + assert!( + program(&path) + .unwrap() + .set_test_timeout(NonZeroU64::MIN) + .is_err() + ); + } + #[test] fn program_bundle_holds_the_program_and_nextest_config() { let dir = tempfile::tempdir().unwrap(); diff --git a/tests/runner/src/execute.rs b/tests/runner/src/execute.rs index 9432f6a629..1492949e5b 100644 --- a/tests/runner/src/execute.rs +++ b/tests/runner/src/execute.rs @@ -34,7 +34,8 @@ const READY_TIMEOUT_SECS: u64 = 300; /// How long the test run may take in total. Individual tests are bounded by /// the nextest profile's slow-timeout; this catches a run that stops making /// progress some other way. -const RUN_TIMEOUT: Duration = Duration::from_mins(45); +const RUN_TIMEOUT: Duration = Duration::from_mins(RUN_TIMEOUT_MINUTES); +pub const RUN_TIMEOUT_MINUTES: u64 = 45; /// Slack beyond the readiness check's own timeout for SSH and process start. const READY_SLACK: Duration = Duration::from_mins(1); /// nextest's exit code when a test failed, as opposed to nextest itself diff --git a/tests/runner/src/main.rs b/tests/runner/src/main.rs index 5f9f7c032c..4fa18a507d 100644 --- a/tests/runner/src/main.rs +++ b/tests/runner/src/main.rs @@ -8,7 +8,7 @@ //! provides the guest cross-compilation toolchain, QEMU, Ansible, and the //! tmachine configuration. -use std::num::NonZeroUsize; +use std::num::{NonZeroU64, NonZeroUsize}; use std::path::{Path, PathBuf}; use std::process::ExitCode; @@ -88,6 +88,16 @@ struct RunArgs { /// Maximum number of tests nextest runs at once [default: 1]. #[arg(long, value_name = "N")] test_threads: Option, + /// Terminate each test after this many minutes instead of two. It applies + /// to every test in the run, so put slow tests in rows of their own. It + /// must be shorter than the whole run's limit. + #[arg( + long, + value_name = "MINUTES", + conflicts_with = "program", + value_parser = clap::value_parser!(u64).range(1..execute::RUN_TIMEOUT_MINUTES) + )] + test_timeout_minutes: Option, /// The gateway name the installer registers with the CLI. The packaged /// installers register `openshell`. #[arg(long, default_value = "openshell")] @@ -175,6 +185,9 @@ async fn run(args: RunArgs) -> Result { .await .context("build task panicked")?? }; + if let Some(minutes) = args.test_timeout_minutes.and_then(NonZeroU64::new) { + bundle.set_test_timeout(minutes)?; + } let tmachine = load_tmachine(&root)?; let status = execute::run( @@ -285,6 +298,30 @@ mod tests { } } + #[test] + fn test_timeout_is_minutes_below_the_run_limit_for_nextest_bundles() { + let args = [ + "runner", + "run", + "--environment", + "ubuntu-k3s", + "--installer", + "k3s-ha", + "--family", + "drivers/kubernetes", + "--test-timeout-minutes", + ]; + let parse = |extra: &[&str]| Cli::try_parse_from(args.iter().chain(extra)); + let Command::Run(run) = parse(&["20", "--bundle", "b"]).unwrap().command else { + panic!("not run") + }; + assert_eq!(run.test_timeout_minutes, Some(20)); + for bad in ["0", "45", "1.5", "20m"] { + assert!(parse(&[bad]).is_err(), "{bad}"); + } + assert!(parse(&["20", "--program", "p"]).is_err()); + } + #[test] fn family_is_a_path_under_tests_suites() { let root = Path::new("/repo"); From 7a323700e78c8a59959a39a34a6e1bfd578ea956 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Thu, 3 Dec 2026 17:20:39 -0800 Subject: [PATCH 2/5] test(runner): take the per-test timeout in seconds --test-timeout and the test_timeout_secs row column match testkit's run --timeout and the program profile, which terminate a test after one period of that length. Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 10 +++++----- TESTING.md | 6 +++--- tests/runner/src/bundle.rs | 27 +++++++++++++-------------- tests/runner/src/execute.rs | 3 +-- tests/runner/src/main.rs | 29 +++++++++++++++-------------- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index d906098db5..7dd740673c 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -91,8 +91,8 @@ jobs: # installer registers with the CLI: `openshell` for the packages, # `tmachine` for the k3s and binaries installers. A row without a # package runs every package in the workspace; each driver suite is a - # workspace of its own. `test_threads` and `test_timeout_minutes` - # pass `--test-threads` and `--test-timeout-minutes` to the runner. + # workspace of its own. `test_threads` and `test_timeout_secs` + # pass `--test-threads` and `--test-timeout` to the runner. rows='[ {"environment":"ubuntu-docker-rootful","installer":"deb","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04","test_threads":4}, {"environment":"ubuntu-docker-rootful","installer":"deb-external-docker-driver","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04","external_driver":true,"test_threads":4}, @@ -291,7 +291,7 @@ jobs: GATEWAY: ${{ matrix.gateway }} DISRUPTION: ${{ matrix.disruption }} TEST_THREADS: ${{ matrix.test_threads }} - TEST_TIMEOUT_MINUTES: ${{ matrix.test_timeout_minutes }} + TEST_TIMEOUT_SECS: ${{ matrix.test_timeout_secs }} run: | # The tests this environment can't pass yet; the runner passes the # variable on to the guest. @@ -325,8 +325,8 @@ jobs: if [ -n "${TEST_THREADS}" ]; then selection+=(--test-threads "${TEST_THREADS}") fi - if [ -n "${TEST_TIMEOUT_MINUTES}" ]; then - selection+=(--test-timeout-minutes "${TEST_TIMEOUT_MINUTES}") + if [ -n "${TEST_TIMEOUT_SECS}" ]; then + selection+=(--test-timeout "${TEST_TIMEOUT_SECS}") fi # A continuity row seeds state, applies the disruption, and verifies. if [ -n "${DISRUPTION}" ]; then diff --git a/TESTING.md b/TESTING.md index 5d4fa62fa8..912f520657 100644 --- a/TESTING.md +++ b/TESTING.md @@ -331,9 +331,9 @@ the runner builds the suite or uses `--bundle` or `--program`. The default is one. CI rows can opt in with `test_threads`. The runner terminates a test after two minutes, or after 15 minutes for -`--program`. `--test-timeout-minutes N` raises the limit to N minutes (below -the run's 45-minute limit) for a built or `--bundle` run, and CI rows set it -with `test_timeout_minutes`. The limit applies to every test in the row, so a +`--program`. `--test-timeout ` sets the limit (below the run's 45-minute +limit) for a built or `--bundle` run, and CI rows set it with +`test_timeout_secs`. The limit applies to every test in the row, so a row runs at its slowest test's limit: put slow tests in rows of their own. Keep it above the test's own step timeouts, so those report first. diff --git a/tests/runner/src/bundle.rs b/tests/runner/src/bundle.rs index d0aad09a92..01726e1786 100644 --- a/tests/runner/src/bundle.rs +++ b/tests/runner/src/bundle.rs @@ -37,17 +37,16 @@ pub const READY_BINARY: &str = "testkit-ready"; /// instead of holding the lane until the job times out. const SLOW_PERIOD_SECS: u64 = 30; const SLOW_TERMINATE_AFTER: u64 = 4; -/// The slow period when a row sets its own per-test timeout in minutes. -const MINUTE_SECS: u64 = 60; /// How long a terminated test has between SIGTERM and SIGKILL. const GRACE_PERIOD_SECS: u64 = 10; /// The nextest configuration written into a nextest bundle. Each test is -/// terminated after `timeout_minutes`, or after two minutes without one. -fn nextest_config(timeout_minutes: Option) -> String { - let (period, terminate_after) = timeout_minutes - .map_or((SLOW_PERIOD_SECS, SLOW_TERMINATE_AFTER), |minutes| { - (MINUTE_SECS, minutes.get()) +/// terminated after `timeout_secs`, as in a program bundle, or after two +/// minutes without one. +fn nextest_config(timeout_secs: Option) -> String { + let (period, terminate_after) = timeout_secs + .map_or((SLOW_PERIOD_SECS, SLOW_TERMINATE_AFTER), |secs| { + (secs.get(), 1) }); format!( r#"# Written by the OpenShell test runner. @@ -100,15 +99,15 @@ impl Bundle { self.1 } - /// Terminate each test of a nextest bundle after `minutes` instead of - /// two minutes. The bundle is the runner's own copy, so this changes only - /// this run. - pub fn set_test_timeout(&self, minutes: NonZeroU64) -> Result<()> { + /// Terminate each test of a nextest bundle after `secs` seconds instead + /// of two minutes. The bundle is the runner's own copy, so this changes + /// only this run. + pub fn set_test_timeout(&self, secs: NonZeroU64) -> Result<()> { ensure!( self.1 == Kind::Nextest, "a per-test timeout applies to nextest bundles, not to a prebuilt program" ); - std::fs::write(self.path().join(CONFIG), nextest_config(Some(minutes))) + std::fs::write(self.path().join(CONFIG), nextest_config(Some(secs))) .context("write the bundle's nextest config") } } @@ -392,11 +391,11 @@ mod tests { write_bundle(dir.path(), "features", &[]); let bundle = prebuilt(dir.path(), "features", &[]).unwrap(); bundle - .set_test_timeout(NonZeroU64::new(20).unwrap()) + .set_test_timeout(NonZeroU64::new(1200).unwrap()) .unwrap(); let config = std::fs::read_to_string(bundle.path().join(CONFIG)).unwrap(); assert!(config.contains( - r#"slow-timeout = { period = "60s", terminate-after = 20, grace-period = "10s" }"# + r#"slow-timeout = { period = "1200s", terminate-after = 1, grace-period = "10s" }"# )); assert!(config.contains(&format!("[profile.{PROFILE}.junit]\n"))); // The prebuilt bundle itself is unchanged. diff --git a/tests/runner/src/execute.rs b/tests/runner/src/execute.rs index 1492949e5b..8062d01ac7 100644 --- a/tests/runner/src/execute.rs +++ b/tests/runner/src/execute.rs @@ -34,8 +34,7 @@ const READY_TIMEOUT_SECS: u64 = 300; /// How long the test run may take in total. Individual tests are bounded by /// the nextest profile's slow-timeout; this catches a run that stops making /// progress some other way. -const RUN_TIMEOUT: Duration = Duration::from_mins(RUN_TIMEOUT_MINUTES); -pub const RUN_TIMEOUT_MINUTES: u64 = 45; +pub const RUN_TIMEOUT: Duration = Duration::from_mins(45); /// Slack beyond the readiness check's own timeout for SSH and process start. const READY_SLACK: Duration = Duration::from_mins(1); /// nextest's exit code when a test failed, as opposed to nextest itself diff --git a/tests/runner/src/main.rs b/tests/runner/src/main.rs index 4fa18a507d..c6e0bca74b 100644 --- a/tests/runner/src/main.rs +++ b/tests/runner/src/main.rs @@ -88,16 +88,16 @@ struct RunArgs { /// Maximum number of tests nextest runs at once [default: 1]. #[arg(long, value_name = "N")] test_threads: Option, - /// Terminate each test after this many minutes instead of two. It applies - /// to every test in the run, so put slow tests in rows of their own. It - /// must be shorter than the whole run's limit. + /// Terminate each test after this many seconds instead of two minutes. It + /// applies to every test in the run, so put slow tests in rows of their + /// own. It must be shorter than the whole run's limit. #[arg( long, - value_name = "MINUTES", + value_name = "SECS", conflicts_with = "program", - value_parser = clap::value_parser!(u64).range(1..execute::RUN_TIMEOUT_MINUTES) + value_parser = clap::value_parser!(u64).range(1..execute::RUN_TIMEOUT.as_secs()) )] - test_timeout_minutes: Option, + test_timeout: Option, /// The gateway name the installer registers with the CLI. The packaged /// installers register `openshell`. #[arg(long, default_value = "openshell")] @@ -185,8 +185,8 @@ async fn run(args: RunArgs) -> Result { .await .context("build task panicked")?? }; - if let Some(minutes) = args.test_timeout_minutes.and_then(NonZeroU64::new) { - bundle.set_test_timeout(minutes)?; + if let Some(secs) = args.test_timeout.and_then(NonZeroU64::new) { + bundle.set_test_timeout(secs)?; } let tmachine = load_tmachine(&root)?; @@ -299,7 +299,7 @@ mod tests { } #[test] - fn test_timeout_is_minutes_below_the_run_limit_for_nextest_bundles() { + fn test_timeout_is_seconds_below_the_run_limit_for_nextest_bundles() { let args = [ "runner", "run", @@ -309,17 +309,18 @@ mod tests { "k3s-ha", "--family", "drivers/kubernetes", - "--test-timeout-minutes", + "--test-timeout", ]; let parse = |extra: &[&str]| Cli::try_parse_from(args.iter().chain(extra)); - let Command::Run(run) = parse(&["20", "--bundle", "b"]).unwrap().command else { + let Command::Run(run) = parse(&["1200", "--bundle", "b"]).unwrap().command else { panic!("not run") }; - assert_eq!(run.test_timeout_minutes, Some(20)); - for bad in ["0", "45", "1.5", "20m"] { + assert_eq!(run.test_timeout, Some(1200)); + assert!(parse(&["2699"]).is_ok()); + for bad in ["0", "2700", "1.5", "20m"] { assert!(parse(&[bad]).is_err(), "{bad}"); } - assert!(parse(&["20", "--program", "p"]).is_err()); + assert!(parse(&["1200", "--program", "p"]).is_err()); } #[test] From 1b5514e85f71ee4509b1f7299223d8126d5dc9ff Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Fri, 4 Dec 2026 10:33:43 -0800 Subject: [PATCH 3/5] test(runner): replace a read-only bundle config when setting the timeout The bundle copy keeps the source file's mode, so writing the timeout into a read-only nextest.toml failed. Write a new file and rename it over the copy instead. Signed-off-by: Matthew Grossman --- tests/runner/src/bundle.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/runner/src/bundle.rs b/tests/runner/src/bundle.rs index 01726e1786..60f9118656 100644 --- a/tests/runner/src/bundle.rs +++ b/tests/runner/src/bundle.rs @@ -107,8 +107,13 @@ impl Bundle { self.1 == Kind::Nextest, "a per-test timeout applies to nextest bundles, not to a prebuilt program" ); - std::fs::write(self.path().join(CONFIG), nextest_config(Some(secs))) - .context("write the bundle's nextest config") + // The copy keeps the source's mode, which may be read-only, so + // replace the file rather than writing into it. + let staged = self.path().join(format!("{CONFIG}.new")); + std::fs::write(&staged, nextest_config(Some(secs))) + .context("write the bundle's nextest config")?; + std::fs::rename(&staged, self.path().join(CONFIG)) + .context("replace the bundle's nextest config") } } @@ -389,10 +394,14 @@ mod tests { fn test_timeout_replaces_the_bundle_slow_timeout() { let dir = tempfile::tempdir().unwrap(); write_bundle(dir.path(), "features", &[]); + // A read-only source config, as in a read-only bundle directory. + let read_only = std::fs::Permissions::from_mode(0o444); + std::fs::set_permissions(dir.path().join(CONFIG), read_only).unwrap(); let bundle = prebuilt(dir.path(), "features", &[]).unwrap(); bundle .set_test_timeout(NonZeroU64::new(1200).unwrap()) .unwrap(); + assert!(!bundle.path().join(format!("{CONFIG}.new")).exists()); let config = std::fs::read_to_string(bundle.path().join(CONFIG)).unwrap(); assert!(config.contains( r#"slow-timeout = { period = "1200s", terminate-after = 1, grace-period = "10s" }"# @@ -403,6 +412,11 @@ mod tests { std::fs::read(dir.path().join(CONFIG)).unwrap(), CONFIG.as_bytes() ); + let mode = std::fs::metadata(dir.path().join(CONFIG)) + .unwrap() + .permissions() + .mode(); + assert_eq!(mode & 0o777, 0o444); let program_dir = tempfile::tempdir().unwrap(); let path = program_dir.path().join("openshell-conformance"); From c8ac31370965559713de9eae2710df5177d45c73 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Fri, 4 Dec 2026 11:24:58 -0800 Subject: [PATCH 4/5] test(runner): remove the bundle config before writing the timeout Staging the new config under a fixed name could collide with an existing bundle entry. Remove the copied nextest.toml and write a new one instead; both need only the run directory's permissions. Signed-off-by: Matthew Grossman --- tests/runner/src/bundle.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/runner/src/bundle.rs b/tests/runner/src/bundle.rs index 60f9118656..355ecf8c66 100644 --- a/tests/runner/src/bundle.rs +++ b/tests/runner/src/bundle.rs @@ -109,11 +109,10 @@ impl Bundle { ); // The copy keeps the source's mode, which may be read-only, so // replace the file rather than writing into it. - let staged = self.path().join(format!("{CONFIG}.new")); - std::fs::write(&staged, nextest_config(Some(secs))) - .context("write the bundle's nextest config")?; - std::fs::rename(&staged, self.path().join(CONFIG)) - .context("replace the bundle's nextest config") + let config = self.path().join(CONFIG); + std::fs::remove_file(&config).context("remove the bundle's nextest config")?; + std::fs::write(&config, nextest_config(Some(secs))) + .context("write the bundle's nextest config") } } @@ -397,11 +396,18 @@ mod tests { // A read-only source config, as in a read-only bundle directory. let read_only = std::fs::Permissions::from_mode(0o444); std::fs::set_permissions(dir.path().join(CONFIG), read_only).unwrap(); + // An unrelated bundle entry whose name a staged config could take. + let neighbor = format!("{CONFIG}.new"); + std::fs::create_dir(dir.path().join(&neighbor)).unwrap(); + std::fs::write(dir.path().join(&neighbor).join("keep"), b"keep").unwrap(); let bundle = prebuilt(dir.path(), "features", &[]).unwrap(); bundle .set_test_timeout(NonZeroU64::new(1200).unwrap()) .unwrap(); - assert!(!bundle.path().join(format!("{CONFIG}.new")).exists()); + assert_eq!( + std::fs::read(bundle.path().join(&neighbor).join("keep")).unwrap(), + b"keep" + ); let config = std::fs::read_to_string(bundle.path().join(CONFIG)).unwrap(); assert!(config.contains( r#"slow-timeout = { period = "1200s", terminate-after = 1, grace-period = "10s" }"# From 095796568d75f01eefcf5018c7287dd48e0970af Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Fri, 4 Dec 2026 11:49:16 -0800 Subject: [PATCH 5/5] test(runner): write the nextest config per run instead of into the bundle nextest takes the per-test timeout only from its config file. Rather than rewriting the config inside a copied bundle, which broke on read-only copies and needed a staging name, the runner now generates the config for each run, copies it into the guest outside the bundle, and passes it with --config-file. Bundles no longer carry nextest.toml, and the timeout is a run setting like --test-threads. Signed-off-by: Matthew Grossman --- tests/runner/src/bundle.rs | 102 +++++++++++++----------------------- tests/runner/src/execute.rs | 17 ++++-- tests/runner/src/main.rs | 4 +- 3 files changed, 51 insertions(+), 72 deletions(-) diff --git a/tests/runner/src/bundle.rs b/tests/runner/src/bundle.rs index 355ecf8c66..2b4b82bb19 100644 --- a/tests/runner/src/bundle.rs +++ b/tests/runner/src/bundle.rs @@ -4,10 +4,11 @@ //! Building a family's test bundle for the guest, on the host. //! //! A bundle is a directory holding a nextest archive built for the guest target, -//! the family workspace's `Cargo.toml` files (for `--workspace-remap`), a -//! `nextest` config with the runner's `JUnit` profile, and `testkit-ready`, -//! which waits for the gateway before the tests run. The guest needs only the -//! `cargo-nextest` binary to run it. +//! the family workspace's `Cargo.toml` files (for `--workspace-remap`), and +//! `testkit-ready`, which waits for the gateway before the tests run. The +//! guest needs only the `cargo-nextest` binary to run it. The runner writes +//! the nextest config for each run ([`Bundle::nextest_config`]), so a bundle +//! is never changed after it is built. //! //! `build` writes a bundle to a directory, so CI can build it once and every //! row can run it (`run --bundle`). A `bundle.json` in it names the family @@ -40,10 +41,10 @@ const SLOW_TERMINATE_AFTER: u64 = 4; /// How long a terminated test has between SIGTERM and SIGKILL. const GRACE_PERIOD_SECS: u64 = 10; -/// The nextest configuration written into a nextest bundle. Each test is -/// terminated after `timeout_secs`, as in a program bundle, or after two -/// minutes without one. -fn nextest_config(timeout_secs: Option) -> String { +/// The nextest configuration for a nextest bundle. Each test is terminated +/// after `timeout_secs`, as in a program bundle, or after two minutes without +/// one. +fn archive_config(timeout_secs: Option) -> String { let (period, terminate_after) = timeout_secs .map_or((SLOW_PERIOD_SECS, SLOW_TERMINATE_AFTER), |secs| { (secs.get(), 1) @@ -65,8 +66,6 @@ pub const PROGRAM_BINARY: &str = "test-program"; /// The nextest archive in a nextest bundle. const ARCHIVE: &str = "tests.tar.zst"; -/// The nextest config in a nextest bundle. -const CONFIG: &str = "nextest.toml"; /// What a nextest bundle was built from. const MANIFEST: &str = "bundle.json"; @@ -99,20 +98,20 @@ impl Bundle { self.1 } - /// Terminate each test of a nextest bundle after `secs` seconds instead - /// of two minutes. The bundle is the runner's own copy, so this changes - /// only this run. - pub fn set_test_timeout(&self, secs: NonZeroU64) -> Result<()> { - ensure!( - self.1 == Kind::Nextest, - "a per-test timeout applies to nextest bundles, not to a prebuilt program" - ); - // The copy keeps the source's mode, which may be read-only, so - // replace the file rather than writing into it. - let config = self.path().join(CONFIG); - std::fs::remove_file(&config).context("remove the bundle's nextest config")?; - std::fs::write(&config, nextest_config(Some(secs))) - .context("write the bundle's nextest config") + /// The nextest config to run this bundle with, with the runner's + /// profile. A nextest bundle's tests are terminated after `timeout_secs` + /// instead of two minutes. + pub fn nextest_config(&self, timeout_secs: Option) -> Result { + match self.1 { + Kind::Nextest => Ok(archive_config(timeout_secs)), + Kind::Program => { + ensure!( + timeout_secs.is_none(), + "a per-test timeout applies to nextest bundles, not to a prebuilt program" + ); + Ok(PROGRAM_CONFIG.to_string()) + } + } } } @@ -128,11 +127,10 @@ pub fn program(program: &Path) -> Result { let dir = tempfile::tempdir().context("create bundle directory")?; std::fs::copy(program, dir.path().join(PROGRAM_BINARY)) .with_context(|| format!("copy {}", program.display()))?; - std::fs::write(dir.path().join(CONFIG), PROGRAM_CONFIG)?; Ok(Bundle(dir, Kind::Program)) } -/// The nextest configuration written into a program bundle, shared with the +/// The nextest configuration for a program bundle, shared with the /// host-lane wrapper (`e2e/support/conformance.sh`). const PROGRAM_CONFIG: &str = include_str!("program-nextest.toml"); @@ -242,7 +240,6 @@ pub fn build(root: &Path, family: &str, packages: &[String], out: &Path) -> Resu run(&mut command).with_context(|| format!("build the {} test archive", workspace.display()))?; copy_manifests(&workspace, out)?; - std::fs::write(out.join(CONFIG), nextest_config(None))?; std::fs::copy(&ready, out.join(READY_BINARY)) .with_context(|| format!("copy {}", ready.display()))?; let manifest = Manifest { @@ -263,7 +260,7 @@ pub fn prebuilt(dir: &Path, family: &str, packages: &[String]) -> Result .with_context(|| format!("parse {}", dir.join(MANIFEST).display()))?; check_selection(&manifest, family, packages) .with_context(|| format!("--bundle {}", dir.display()))?; - for name in [ARCHIVE, CONFIG, READY_BINARY] { + for name in [ARCHIVE, READY_BINARY] { ensure!( dir.join(name).is_file(), "{} is not a test bundle: it has no {name}", @@ -383,71 +380,44 @@ mod tests { #[test] fn nextest_profile_stops_a_hung_test_after_two_minutes() { - let config = nextest_config(None); + let config = archive_config(None); assert!(config.contains( r#"slow-timeout = { period = "30s", terminate-after = 4, grace-period = "10s" }"# )); } #[test] - fn test_timeout_replaces_the_bundle_slow_timeout() { + fn test_timeout_sets_the_nextest_bundle_slow_timeout() { let dir = tempfile::tempdir().unwrap(); write_bundle(dir.path(), "features", &[]); - // A read-only source config, as in a read-only bundle directory. - let read_only = std::fs::Permissions::from_mode(0o444); - std::fs::set_permissions(dir.path().join(CONFIG), read_only).unwrap(); - // An unrelated bundle entry whose name a staged config could take. - let neighbor = format!("{CONFIG}.new"); - std::fs::create_dir(dir.path().join(&neighbor)).unwrap(); - std::fs::write(dir.path().join(&neighbor).join("keep"), b"keep").unwrap(); let bundle = prebuilt(dir.path(), "features", &[]).unwrap(); - bundle - .set_test_timeout(NonZeroU64::new(1200).unwrap()) - .unwrap(); - assert_eq!( - std::fs::read(bundle.path().join(&neighbor).join("keep")).unwrap(), - b"keep" - ); - let config = std::fs::read_to_string(bundle.path().join(CONFIG)).unwrap(); + let config = bundle.nextest_config(NonZeroU64::new(1200)).unwrap(); assert!(config.contains( r#"slow-timeout = { period = "1200s", terminate-after = 1, grace-period = "10s" }"# )); assert!(config.contains(&format!("[profile.{PROFILE}.junit]\n"))); - // The prebuilt bundle itself is unchanged. - assert_eq!( - std::fs::read(dir.path().join(CONFIG)).unwrap(), - CONFIG.as_bytes() - ); - let mode = std::fs::metadata(dir.path().join(CONFIG)) - .unwrap() - .permissions() - .mode(); - assert_eq!(mode & 0o777, 0o444); + assert_eq!(bundle.nextest_config(None).unwrap(), archive_config(None)); let program_dir = tempfile::tempdir().unwrap(); let path = program_dir.path().join("openshell-conformance"); std::fs::write(&path, b"binary").unwrap(); - assert!( - program(&path) - .unwrap() - .set_test_timeout(NonZeroU64::MIN) - .is_err() - ); + let program = program(&path).unwrap(); + assert_eq!(program.nextest_config(None).unwrap(), PROGRAM_CONFIG); + assert!(program.nextest_config(Some(NonZeroU64::MIN)).is_err()); } #[test] - fn program_bundle_holds_the_program_and_nextest_config() { + fn program_bundle_holds_the_program_alone() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("openshell-conformance"); std::fs::write(&path, b"binary").unwrap(); let bundle = program(&path).unwrap(); assert_eq!(bundle.kind(), Kind::Program); - let mut names: Vec<_> = std::fs::read_dir(bundle.path()) + let names: Vec<_> = std::fs::read_dir(bundle.path()) .unwrap() .map(|entry| entry.unwrap().file_name()) .collect(); - names.sort(); - assert_eq!(names, [CONFIG, PROGRAM_BINARY]); + assert_eq!(names, [PROGRAM_BINARY]); assert!(program(&dir.path().join("missing")).is_err()); } @@ -459,7 +429,7 @@ mod tests { fn write_bundle(dir: &Path, family: &str, packages: &[&str]) { std::fs::create_dir_all(dir.join("host-gateway")).unwrap(); - for name in [ARCHIVE, CONFIG, READY_BINARY, "Cargo.toml"] { + for name in [ARCHIVE, READY_BINARY, "Cargo.toml"] { std::fs::write(dir.join(name), name).unwrap(); } std::fs::write(dir.join("host-gateway/Cargo.toml"), "member").unwrap(); diff --git a/tests/runner/src/execute.rs b/tests/runner/src/execute.rs index 8062d01ac7..b7415bfb41 100644 --- a/tests/runner/src/execute.rs +++ b/tests/runner/src/execute.rs @@ -12,6 +12,7 @@ //! [`crate::test_env`]). use std::fmt; +use std::io::Write; use std::path::Path; use std::process::{ExitCode, ExitStatus, Output}; use std::time::Duration; @@ -25,6 +26,9 @@ use crate::disruption::Disruption; use crate::test_env; const GUEST_DIR: &str = "/var/tmp/openshell-tests"; +/// The run's nextest config in the guest, outside the bundle so no bundle +/// entry can take its place. +const GUEST_CONFIG: &str = "/var/tmp/openshell-tests.nextest.toml"; /// The test log's name, in the guest directory and in the results. const NEXTEST_LOG: &str = "nextest.log"; /// How long the gateway has to become healthy after the environment is up. @@ -125,6 +129,9 @@ pub struct Run<'a> { pub filters: &'a [String], /// Concurrency override for nextest. pub test_threads: Option, + /// Seconds after which nextest terminates each test, instead of two + /// minutes. + pub test_timeout: Option, /// Where `junit.xml`, `nextest.log` and, after a failure, the guest's /// `diagnostics/` go. pub results: &'a Path, @@ -257,9 +264,14 @@ async fn run_tests(session: &Session, run: &Run<'_>) -> Result { let guest = GUEST_DIR; checked( "clear guest directory", - session.exec(&["rm", "-rf", guest]).await?, + session.exec(&["rm", "-rf", guest, GUEST_CONFIG]).await?, )?; session.copy_in(run.bundle.path(), guest).await?; + let mut config = tempfile::NamedTempFile::new().context("create the nextest config")?; + config + .write_all(run.bundle.nextest_config(run.test_timeout)?.as_bytes()) + .context("write the nextest config")?; + session.copy_in(config.path(), GUEST_CONFIG).await?; checked( "prepare guest directory", session @@ -389,7 +401,6 @@ async fn run_selected( let program = format!("{guest}/{PROGRAM_BINARY}"); let archive = format!("{guest}/tests.tar.zst"); let extract = format!("{guest}/extract"); - let config = format!("{guest}/nextest.toml"); let test_threads = run .test_threads .map_or(1, std::num::NonZeroUsize::get) @@ -398,7 +409,7 @@ async fn run_selected( let cargo_metadata = format!("{metadata}/cargo-metadata.json"); let binaries_metadata = format!("{metadata}/binaries-metadata.json"); let export = test_env::export_script(test_env::ENV_DIR); - let mut args: Vec<&str> = vec!["--config-file", &config, "--profile", PROFILE]; + let mut args: Vec<&str> = vec!["--config-file", GUEST_CONFIG, "--profile", PROFILE]; let env_args = std::iter::once("env").chain(env.iter().map(String::as_str)); let mut tests: Vec<_> = env_args.clone().collect(); tests.extend([ diff --git a/tests/runner/src/main.rs b/tests/runner/src/main.rs index c6e0bca74b..e66f9515d9 100644 --- a/tests/runner/src/main.rs +++ b/tests/runner/src/main.rs @@ -185,9 +185,6 @@ async fn run(args: RunArgs) -> Result { .await .context("build task panicked")?? }; - if let Some(secs) = args.test_timeout.and_then(NonZeroU64::new) { - bundle.set_test_timeout(secs)?; - } let tmachine = load_tmachine(&root)?; let status = execute::run( @@ -199,6 +196,7 @@ async fn run(args: RunArgs) -> Result { bundle: &bundle, filters: &filters, test_threads: args.test_threads, + test_timeout: args.test_timeout.and_then(NonZeroU64::new), results: &results, keep: args.keep, disruption,