Skip to content

Commit e185111

Browse files
committed
Auto merge of #6596 - Eh2406:slow-cpu-test, r=dwijnand+alexcrichton
Some CI setups are much slower then the equipment used by Cargo itself This adds a "CARGO_TEST_SLOW_CPU_MULTIPLIER" that increases all the time outs used in the tests, and disables Proptest shrinking on non tty cases. Closes: #6491 CC: #6490, @infinity0
2 parents d5109ad + 7332f67 commit e185111

File tree

7 files changed

+56
-28
lines changed

7 files changed

+56
-28
lines changed

src/cargo/core/resolver/types.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub struct ResolverProgress {
1919
time_to_print: Duration,
2020
printed: bool,
2121
deps_time: Duration,
22+
#[cfg(debug_assertions)]
23+
slow_cpu_multiplier: u64,
2224
}
2325

2426
impl ResolverProgress {
@@ -29,6 +31,14 @@ impl ResolverProgress {
2931
time_to_print: Duration::from_millis(500),
3032
printed: false,
3133
deps_time: Duration::new(0, 0),
34+
// Some CI setups are much slower then the equipment used by Cargo itself.
35+
// Architectures that do not have a modern processor, hardware emulation, ect.
36+
// In the test code we have `slow_cpu_multiplier`, but that is not accessible here.
37+
#[cfg(debug_assertions)]
38+
slow_cpu_multiplier: std::env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER")
39+
.ok()
40+
.and_then(|m| m.parse().ok())
41+
.unwrap_or(1),
3242
}
3343
}
3444
pub fn shell_status(&mut self, config: Option<&Config>) -> CargoResult<()> {
@@ -52,21 +62,27 @@ impl ResolverProgress {
5262
config.shell().status("Resolving", "dependency graph...")?;
5363
}
5464
}
55-
// The largest test in our suite takes less then 5000 ticks
56-
// with all the algorithm improvements.
57-
// If any of them are removed then it takes more than I am willing to measure.
58-
// So lets fail the test fast if we have ben running for two long.
59-
debug_assert!(
60-
self.ticks < 50_000,
61-
"got to 50_000 ticks in {:?}",
62-
self.start.elapsed()
63-
);
64-
// The largest test in our suite takes less then 30 sec
65-
// with all the improvements to how fast a tick can go.
66-
// If any of them are removed then it takes more than I am willing to measure.
67-
// So lets fail the test fast if we have ben running for two long.
68-
if cfg!(debug_assertions) && (self.ticks % 1000 == 0) {
69-
assert!(self.start.elapsed() - self.deps_time < Duration::from_secs(90));
65+
#[cfg(debug_assertions)]
66+
{
67+
// The largest test in our suite takes less then 5000 ticks
68+
// with all the algorithm improvements.
69+
// If any of them are removed then it takes more than I am willing to measure.
70+
// So lets fail the test fast if we have ben running for two long.
71+
assert!(
72+
self.ticks < 50_000,
73+
"got to 50_000 ticks in {:?}",
74+
self.start.elapsed()
75+
);
76+
// The largest test in our suite takes less then 30 sec
77+
// with all the improvements to how fast a tick can go.
78+
// If any of them are removed then it takes more than I am willing to measure.
79+
// So lets fail the test fast if we have ben running for two long.
80+
if self.ticks % 1000 == 0 {
81+
assert!(
82+
self.start.elapsed() - self.deps_time
83+
< Duration::from_secs(self.slow_cpu_multiplier * 90)
84+
);
85+
}
7086
}
7187
Ok(())
7288
}

tests/testsuite/build_script.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use std::fs::{self, File};
33
use std::io;
44
use std::io::prelude::*;
55
use std::thread;
6-
use std::time::Duration;
76

87
use crate::support::paths::CargoPathExt;
98
use crate::support::registry::Package;
109
use crate::support::{basic_manifest, cross_compile, project};
11-
use crate::support::{rustc_host, sleep_ms};
10+
use crate::support::{rustc_host, sleep_ms, slow_cpu_multiplier};
1211
use cargo::util::paths::remove_dir_all;
1312

1413
#[test]
@@ -3174,7 +3173,9 @@ fn switch_features_rerun() {
31743173
p.cargo("build -v --features=foo").run();
31753174
p.rename_run("foo", "with_foo").with_stdout("foo\n").run();
31763175
p.cargo("build -v").run();
3177-
p.rename_run("foo", "without_foo").with_stdout("bar\n").run();
3176+
p.rename_run("foo", "without_foo")
3177+
.with_stdout("bar\n")
3178+
.run();
31783179
p.cargo("build -v --features=foo").run();
31793180
p.rename_run("foo", "with_foo2").with_stdout("foo\n").run();
31803181
}
@@ -3569,7 +3570,7 @@ fn _rename_with_link_search_path(cross: bool) {
35693570
panic!("failed to rename: {}", error);
35703571
}
35713572
println!("assuming {} is spurious, waiting to try again", error);
3572-
thread::sleep(Duration::from_millis(100));
3573+
thread::sleep(slow_cpu_multiplier(100));
35733574
}
35743575

35753576
p2.cargo(&format!("run{}", target_arg))

tests/testsuite/concurrent.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use std::net::TcpListener;
44
use std::process::Stdio;
55
use std::sync::mpsc::channel;
66
use std::thread;
7-
use std::time::Duration;
87
use std::{env, str};
98

109
use crate::support::cargo_process;
1110
use crate::support::git;
1211
use crate::support::install::{assert_has_installed_exe, cargo_home};
1312
use crate::support::registry::Package;
14-
use crate::support::{basic_manifest, execs, project};
13+
use crate::support::{basic_manifest, execs, project, slow_cpu_multiplier};
1514
use git2;
1615

1716
fn pkg(name: &str, vers: &str) {
@@ -526,7 +525,7 @@ fn no_deadlock_with_git_dependencies() {
526525
}
527526

528527
for _ in 0..n_concurrent_builds {
529-
let result = rx.recv_timeout(Duration::from_secs(30)).expect("Deadlock!");
528+
let result = rx.recv_timeout(slow_cpu_multiplier(30)).expect("Deadlock!");
530529
execs().run_output(&result);
531530
}
532531
}

tests/testsuite/death.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::io::{self, Read};
33
use std::net::TcpListener;
44
use std::process::{Child, Stdio};
55
use std::thread;
6-
use std::time::Duration;
76

8-
use crate::support::project;
7+
use crate::{support::project, support::slow_cpu_multiplier};
98

109
#[cfg(unix)]
1110
fn enabled() -> bool {
@@ -121,7 +120,7 @@ fn ctrl_c_kills_everyone() {
121120
Ok(()) => return,
122121
Err(e) => println!("attempt {}: {}", i, e),
123122
}
124-
thread::sleep(Duration::from_millis(100));
123+
thread::sleep(slow_cpu_multiplier(100));
125124
}
126125

127126
panic!(

tests/testsuite/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ proptest! {
3232
// and locally.
3333
cases: 256,
3434
max_shrink_iters:
35-
if env::var("CI").is_ok() {
35+
if env::var("CI").is_ok() || !atty::is(atty::Stream::Stderr) {
3636
// This attempts to make sure that CI will fail fast,
3737
0
3838
} else {

tests/testsuite/support/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,3 +1634,14 @@ pub fn is_coarse_mtime() -> bool {
16341634
// that's tricky to detect, so for now just deal with CI.
16351635
cfg!(target_os = "macos") && env::var("CI").is_ok()
16361636
}
1637+
1638+
/// Some CI setups are much slower then the equipment used by Cargo itself.
1639+
/// Architectures that do not have a modern processor, hardware emulation, ect.
1640+
/// This provides a way for those setups to increase the cut off for all the time based test.
1641+
pub fn slow_cpu_multiplier(main: u64) -> Duration {
1642+
lazy_static::lazy_static! {
1643+
static ref SLOW_CPU_MULTIPLIER: u64 =
1644+
env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER").ok().and_then(|m| m.parse().ok()).unwrap_or(1);
1645+
}
1646+
Duration::from_secs(*SLOW_CPU_MULTIPLIER * main)
1647+
}

tests/testsuite/support/resolver.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use std::cmp::PartialEq;
22
use std::cmp::{max, min};
33
use std::collections::{BTreeMap, HashSet};
44
use std::fmt;
5-
use std::time::{Duration, Instant};
5+
use std::time::Instant;
6+
7+
use crate::support::slow_cpu_multiplier;
68

79
use cargo::core::dependency::Kind;
810
use cargo::core::resolver::{self, Method};
@@ -117,7 +119,7 @@ pub fn resolve_with_config_raw(
117119

118120
// The largest test in our suite takes less then 30 sec.
119121
// So lets fail the test if we have ben running for two long.
120-
assert!(start.elapsed() < Duration::from_secs(60));
122+
assert!(start.elapsed() < slow_cpu_multiplier(60));
121123
resolve
122124
}
123125

0 commit comments

Comments
 (0)