Skip to content

Commit 4be99b2

Browse files
committed
Some CI setups are much slower then the equipment used by Cargo itself
1 parent eb96a36 commit 4be99b2

File tree

6 files changed

+35
-13
lines changed

6 files changed

+35
-13
lines changed

src/cargo/core/resolver/types.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ impl ResolverProgress {
6666
// If any of them are removed then it takes more than I am willing to measure.
6767
// So lets fail the test fast if we have ben running for two long.
6868
if cfg!(debug_assertions) && (self.ticks % 1000 == 0) {
69-
assert!(self.start.elapsed() - self.deps_time < Duration::from_secs(90));
69+
// Some CI setups are much slower then the equipment used by Cargo itself.
70+
// Architectures that do not have a modern processor, hardware emulation, ect.
71+
// In the test code we have `slow_cpu_multiplier`, but that is not accessible here.
72+
lazy_static::lazy_static! {
73+
static ref SLOW_CPU_MULTIPLIER: u64 =
74+
env::var("CARGO_TEST_SLOW_CPU_MULTIPLIER").ok().and_then(|m| m.parse().ok()).unwrap_or(1);
75+
}
76+
assert!(
77+
self.start.elapsed() - self.deps_time
78+
< Duration::from_secs(*SLOW_CPU_MULTIPLIER * 90)
79+
);
7080
}
7181
Ok(())
7282
}

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/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)