From 48d390554583815ddc0ed7dfea2b17d92e3c6b41 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sun, 5 Jan 2025 10:38:42 -0800 Subject: [PATCH] Warn if --jobs >8 Fixes #412 --- NEWS.md | 2 ++ src/options.rs | 5 +++++ tests/jobs.rs | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 79c2b5f0..d6654a03 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ - Fixed: Support crates that use a non-default Cargo registry. Previously, `cargo metadata` failed with "registry index was not found." +- Improved: Warn if `--jobs` is set higher than 8, which is likely to be too high. + ## 25.0.1-pre3 2025-01-05 - Fixed: Build arm64 binaries for macOS. diff --git a/src/options.rs b/src/options.rs index ce2a120b..caa25dbc 100644 --- a/src/options.rs +++ b/src/options.rs @@ -321,6 +321,11 @@ impl Options { test_timeout_multiplier: args.timeout_multiplier.or(config.timeout_multiplier), test_tool: args.test_tool.or(config.test_tool).unwrap_or_default(), }; + if let Some(jobs) = options.jobs { + if jobs >= 8 { + warn!("--jobs={jobs} is probably too high and may overload your machine: each job runs a separate `cargo` process, and cargo may internally start many threads and subprocesses; values <= 8 are usually safe"); + } + } options.error_values.iter().for_each(|e| { if e.starts_with("Err(") { warn!( diff --git a/tests/jobs.rs b/tests/jobs.rs index 786775f9..53d9b10e 100644 --- a/tests/jobs.rs +++ b/tests/jobs.rs @@ -1,4 +1,4 @@ -// Copyright 2022-2023 Martin Pool. +// Copyright 2022 - 2025 Martin Pool. //! Test handling of `--jobs` concurrency option. @@ -43,3 +43,19 @@ fn jobs_option_accepted_and_causes_multiple_threads() { matches.len() ); } + +#[test] +fn warn_about_too_many_jobs() { + let testdata = copy_of_testdata("small_well_tested"); + run() + .arg("mutants") + .arg("-d") + .arg(testdata.path()) + .arg("-j40") + .arg("--shard=0/1000") + .assert() + .stderr(predicates::str::contains( + "WARN --jobs=40 is probably too high", + )) + .success(); +}