Skip to content

Some CI setups are much slower then the equipment used by Cargo itself #6596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<()> {
Expand All @@ -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(())
}
Expand Down
9 changes: 5 additions & 4 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions tests/testsuite/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
5 changes: 2 additions & 3 deletions tests/testsuite/death.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions tests/testsuite/support/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}

Expand Down