diff --git a/src/cargo/core/resolver/types.rs b/src/cargo/core/resolver/types.rs index fa00d413edd..cdef344805b 100644 --- a/src/cargo/core/resolver/types.rs +++ b/src/cargo/core/resolver/types.rs @@ -19,6 +19,8 @@ pub struct ResolverProgress { time_to_print: Duration, printed: bool, deps_time: Duration, + #[cfg(debug_assertions)] + slow_cpu_multiplier: u64, } impl ResolverProgress { @@ -29,6 +31,14 @@ impl ResolverProgress { time_to_print: Duration::from_millis(500), printed: false, deps_time: Duration::new(0, 0), + // Some CI setups are much slower then the equipment used by Cargo itself. + // Architectures that do not have a modern processor, hardware emulation, ect. + // In the test code we have `slow_cpu_multiplier`, but that is not accessible here. + #[cfg(debug_assertions)] + slow_cpu_multiplier: std::env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER") + .ok() + .and_then(|m| m.parse().ok()) + .unwrap_or(1), } } pub fn shell_status(&mut self, config: Option<&Config>) -> CargoResult<()> { @@ -52,21 +62,27 @@ impl ResolverProgress { config.shell().status("Resolving", "dependency graph...")?; } } - // The largest test in our suite takes less then 5000 ticks - // with all the algorithm improvements. - // If any of them are removed then it takes more than I am willing to measure. - // So lets fail the test fast if we have ben running for two long. - debug_assert!( - self.ticks < 50_000, - "got to 50_000 ticks in {:?}", - self.start.elapsed() - ); - // The largest test in our suite takes less then 30 sec - // with all the improvements to how fast a tick can go. - // If any of them are removed then it takes more than I am willing to measure. - // So lets fail the test fast if we have ben running for two long. - if cfg!(debug_assertions) && (self.ticks % 1000 == 0) { - assert!(self.start.elapsed() - self.deps_time < Duration::from_secs(90)); + #[cfg(debug_assertions)] + { + // The largest test in our suite takes less then 5000 ticks + // with all the algorithm improvements. + // If any of them are removed then it takes more than I am willing to measure. + // So lets fail the test fast if we have ben running for two long. + assert!( + self.ticks < 50_000, + "got to 50_000 ticks in {:?}", + self.start.elapsed() + ); + // The largest test in our suite takes less then 30 sec + // with all the improvements to how fast a tick can go. + // If any of them are removed then it takes more than I am willing to measure. + // So lets fail the test fast if we have ben running for two long. + if self.ticks % 1000 == 0 { + assert!( + self.start.elapsed() - self.deps_time + < Duration::from_secs(self.slow_cpu_multiplier * 90) + ); + } } Ok(()) } diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index fb22b7e245f..9c4dd7031f1 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -3,12 +3,11 @@ use std::fs::{self, File}; use std::io; use std::io::prelude::*; use std::thread; -use std::time::Duration; use crate::support::paths::CargoPathExt; use crate::support::registry::Package; use crate::support::{basic_manifest, cross_compile, project}; -use crate::support::{rustc_host, sleep_ms}; +use crate::support::{rustc_host, sleep_ms, slow_cpu_multiplier}; use cargo::util::paths::remove_dir_all; #[test] @@ -3174,7 +3173,9 @@ fn switch_features_rerun() { p.cargo("build -v --features=foo").run(); p.rename_run("foo", "with_foo").with_stdout("foo\n").run(); p.cargo("build -v").run(); - p.rename_run("foo", "without_foo").with_stdout("bar\n").run(); + p.rename_run("foo", "without_foo") + .with_stdout("bar\n") + .run(); p.cargo("build -v --features=foo").run(); p.rename_run("foo", "with_foo2").with_stdout("foo\n").run(); } @@ -3569,7 +3570,7 @@ fn _rename_with_link_search_path(cross: bool) { panic!("failed to rename: {}", error); } println!("assuming {} is spurious, waiting to try again", error); - thread::sleep(Duration::from_millis(100)); + thread::sleep(slow_cpu_multiplier(100)); } p2.cargo(&format!("run{}", target_arg)) diff --git a/tests/testsuite/concurrent.rs b/tests/testsuite/concurrent.rs index 90e7847807c..d30c5786fb3 100644 --- a/tests/testsuite/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -4,14 +4,13 @@ use std::net::TcpListener; use std::process::Stdio; use std::sync::mpsc::channel; use std::thread; -use std::time::Duration; use std::{env, str}; use crate::support::cargo_process; use crate::support::git; use crate::support::install::{assert_has_installed_exe, cargo_home}; use crate::support::registry::Package; -use crate::support::{basic_manifest, execs, project}; +use crate::support::{basic_manifest, execs, project, slow_cpu_multiplier}; use git2; fn pkg(name: &str, vers: &str) { @@ -526,7 +525,7 @@ fn no_deadlock_with_git_dependencies() { } for _ in 0..n_concurrent_builds { - let result = rx.recv_timeout(Duration::from_secs(30)).expect("Deadlock!"); + let result = rx.recv_timeout(slow_cpu_multiplier(30)).expect("Deadlock!"); execs().run_output(&result); } } diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index 78a20e9b458..98316860b3e 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -3,9 +3,8 @@ use std::io::{self, Read}; use std::net::TcpListener; use std::process::{Child, Stdio}; use std::thread; -use std::time::Duration; -use crate::support::project; +use crate::{support::project, support::slow_cpu_multiplier}; #[cfg(unix)] fn enabled() -> bool { @@ -121,7 +120,7 @@ fn ctrl_c_kills_everyone() { Ok(()) => return, Err(e) => println!("attempt {}: {}", i, e), } - thread::sleep(Duration::from_millis(100)); + thread::sleep(slow_cpu_multiplier(100)); } panic!( diff --git a/tests/testsuite/resolve.rs b/tests/testsuite/resolve.rs index 38407f01ff4..41b51fb9132 100644 --- a/tests/testsuite/resolve.rs +++ b/tests/testsuite/resolve.rs @@ -32,7 +32,7 @@ proptest! { // and locally. cases: 256, max_shrink_iters: - if env::var("CI").is_ok() { + if env::var("CI").is_ok() || !atty::is(atty::Stream::Stderr) { // This attempts to make sure that CI will fail fast, 0 } else { diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index 6498a000142..72dbc46ce0f 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -1634,3 +1634,14 @@ pub fn is_coarse_mtime() -> bool { // that's tricky to detect, so for now just deal with CI. cfg!(target_os = "macos") && env::var("CI").is_ok() } + +/// Some CI setups are much slower then the equipment used by Cargo itself. +/// Architectures that do not have a modern processor, hardware emulation, ect. +/// This provides a way for those setups to increase the cut off for all the time based test. +pub fn slow_cpu_multiplier(main: u64) -> Duration { + lazy_static::lazy_static! { + static ref SLOW_CPU_MULTIPLIER: u64 = + env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER").ok().and_then(|m| m.parse().ok()).unwrap_or(1); + } + Duration::from_secs(*SLOW_CPU_MULTIPLIER * main) +} diff --git a/tests/testsuite/support/resolver.rs b/tests/testsuite/support/resolver.rs index d424d61b34f..79604c65de8 100644 --- a/tests/testsuite/support/resolver.rs +++ b/tests/testsuite/support/resolver.rs @@ -2,7 +2,9 @@ use std::cmp::PartialEq; use std::cmp::{max, min}; use std::collections::{BTreeMap, HashSet}; use std::fmt; -use std::time::{Duration, Instant}; +use std::time::Instant; + +use crate::support::slow_cpu_multiplier; use cargo::core::dependency::Kind; use cargo::core::resolver::{self, Method}; @@ -117,7 +119,7 @@ pub fn resolve_with_config_raw( // The largest test in our suite takes less then 30 sec. // So lets fail the test if we have ben running for two long. - assert!(start.elapsed() < Duration::from_secs(60)); + assert!(start.elapsed() < slow_cpu_multiplier(60)); resolve }