Skip to content

Commit

Permalink
Warn if --jobs >8
Browse files Browse the repository at this point in the history
Fixes #412
  • Loading branch information
sourcefrog committed Jan 5, 2025
1 parent 5107f01 commit 48d3905
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
18 changes: 17 additions & 1 deletion tests/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Martin Pool.
// Copyright 2022 - 2025 Martin Pool.

//! Test handling of `--jobs` concurrency option.
Expand Down Expand Up @@ -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();
}

0 comments on commit 48d3905

Please sign in to comment.