Skip to content

Commit

Permalink
Multiple build timeout by n_jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Jul 5, 2024
1 parent 0fa6d40 commit 6feefe9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cargo-mutants changelog

## Unreleased

- Fixed: The auto-set timeout for building mutants is now 2 times the baseline build time times the number of jobs, with a minimum of 20 seconds. This was changed because builds of mutants contend with each other for access to CPUs and may be slower than the baseline build.

## 24.5.0

- Fixed: Follow `path` attributes on `mod` statements.
Expand Down
4 changes: 3 additions & 1 deletion book/src/timeouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ build and test the unmodified tree (baseline).

The default timeouts are:

- `cargo build`/`cargo check`: 2 times the baseline build time (with a minimum of 20 seconds)
- `cargo build`/`cargo check`: 2 times the baseline build time times the number of jobs (with a minimum of 20 seconds)
- `cargo test`: 5 times baseline test time (with a minimum of 20 seconds)

The build timeout scales with the number of jobs to reflect that cargo often spawns many jobs, and so builds run in parallel are likely to take longer than the baseline, which has no external parallelism.

The minimum of 20 seconds for the test timeout can be overridden by the
`--minimum-test-timeout` option or the `CARGO_MUTANTS_MINIMUM_TEST_TIMEOUT`
environment variable, measured in seconds.
Expand Down
1 change: 1 addition & 0 deletions src/lab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn test_mutants(
}
BaselineStrategy::Skip => Timeouts::without_baseline(&options),
};
debug!(?timeouts);
let mut build_dirs = vec![build_dir];
let jobs = max(1, min(options.jobs.unwrap_or(1), mutants.len()));
for i in 1..jobs {
Expand Down
16 changes: 13 additions & 3 deletions src/timeouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ fn phase_timeout(
if let Some(timeout) = explicit_timeout {
return timeout;
}

match baseline_duration {
Some(_) if options.in_place && phase != Phase::Test => {
warn_fallback_timeout(phase.name(), "--in-place");
Expand All @@ -73,7 +72,6 @@ fn phase_timeout(
minimum,
Duration::from_secs((baseline_duration.as_secs_f64() * multiplier).ceil() as u64),
);

if options.show_times {
info!(
"Auto-set {} timeout to {}",
Expand Down Expand Up @@ -107,7 +105,9 @@ fn build_timeout(baseline_duration: Option<Duration>, options: &Options) -> Dura
options.build_timeout,
baseline_duration,
Duration::from_secs(20),
options.build_timeout_multiplier.unwrap_or(2.0),
options
.build_timeout_multiplier
.unwrap_or(2.0 * options.jobs.unwrap_or(1) as f64),
options,
)
}
Expand Down Expand Up @@ -157,6 +157,16 @@ mod test {
);
}

#[test]
fn mutant_build_timeout_with_multiple_jobs() {
let args = Args::parse_from(["mutants", "--jobs=4"]);
let options = Options::new(&args, &Config::default()).unwrap();
assert_eq!(
build_timeout(Some(Duration::from_secs(40)), &options),
Duration::from_secs(40 * 2 * 4),
);
}

#[test]
fn build_timeout_is_affected_by_in_place_build() {
let args = Args::parse_from(["mutants", "--build-timeout-multiplier", "1.5", "--in-place"]);
Expand Down

0 comments on commit 6feefe9

Please sign in to comment.