-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: improve test resilience and run style checks within `cargo nextes…
…t` (#9608) I got absolutely fed up with waiting for prerequisite infrastructure work for #9290 (why does it have to be _that_ hard?) However the PR in question had some other important improvements that do not necessarily *rely* on changes to said infrastructure to work. In particular: * `nextest` now retries failing tests a few times before giving up, to make sure they aren't spuriously failing; * This should help some timing out integration tests in particular, as those often fail because of some deadlockish situation in my experience. * style checks still run with `cargo nextest` – unfortunately that means that in CI this will run these checks multiple times, but that doesn’t sound particularly terrible of a tradeoff (especially if the other changes mean we won't be retrying entire test suites as often anymore;) * This should allow for a greater portion of the test suite to run on Macs – unfortunately not verified by the CI, but people do complain and this should make the situation better. cc #9367
- Loading branch information
Showing
15 changed files
with
149 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
[profile.default] | ||
slow-timeout = { period = "60s", terminate-after = 2, grace-period = "0s" } | ||
# FIXME(nagisa): use --profile ci in CI instead when we manage to modify CI scripts... | ||
retries = { backoff = "fixed", count = 3, delay = "1s" } | ||
failure-output = "final" | ||
|
||
[[profile.default.overrides]] | ||
filter = 'test(test_full_estimator)' | ||
slow-timeout = { period = "10m", terminate-after = 3 } | ||
threads-required = 4 | ||
|
||
[[profile.default.overrides]] | ||
filter = 'package(style-tests)' | ||
slow-timeout = { period = "120s", terminate-after = 5 } | ||
threads-required = 4 | ||
|
||
# Unfortunately no support for inheriting profiles yet: | ||
# https://github.com/nextest-rs/nextest/issues/387 | ||
[profile.ci] | ||
slow-timeout = { period = "120s", terminate-after = 5 } | ||
# Try a few times before failing the whole test suite on a potentially spurious tests. | ||
# The hope is that people will fix the spurious tests as they encounter them locally... | ||
retries = { backoff = "fixed", count = 3, delay = "1s" } | ||
failure-output = "final" | ||
fail-fast = false | ||
|
||
[[profile.ci.overrides]] | ||
filter = 'test(test_full_estimator)' | ||
slow-timeout = { period = "10m", terminate-after = 3 } | ||
threads-required = 4 | ||
|
||
[[profile.ci.overrides]] | ||
filter = 'package(style-tests)' | ||
slow-timeout = { period = "120s", terminate-after = 5 } | ||
threads-required = 4 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
#![cfg(target_arch = "x86_64")] | ||
|
||
mod sys; | ||
pub use sys::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "style-tests" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
description = "An entry point for miscelaneous (stylistic) workspace-wide tests" | ||
authors = ["Near Inc <hello@nearprotocol.com>"] | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#![cfg(test)] | ||
use std::{ | ||
ffi::{OsStr, OsString}, | ||
path::PathBuf, | ||
process::Command, | ||
}; | ||
|
||
/// Add common cargo arguments for tests run by this code. | ||
fn cargo_env(cmd: &mut Command) { | ||
// Set the working directory to the project root, rather than using whatever default nextest | ||
// gives us. | ||
let style_root = std::env::var_os("CARGO_MANIFEST_DIR").unwrap_or(OsString::from("./")); | ||
let wp_root: PathBuf = [&style_root, OsStr::new(".."), OsStr::new("..")].into_iter().collect(); | ||
cmd.current_dir(&wp_root); | ||
|
||
// Use a different target directory to avoid invalidating any cache after tests are run (so | ||
// that running `cargo nextest` twice does not rebuild half of the workspace on the 2nd | ||
// rebuild. Unfortunately cargo itself does not readily expose this information to us, so we | ||
// have to guess a little as to where this directory might end up. | ||
// | ||
// NB: We aren't using a temporary directory proper here in order to *allow* keeping cache | ||
// between individual `clippy` runs and such. | ||
let target_dir: PathBuf = | ||
[wp_root.as_os_str(), OsStr::new("target"), OsStr::new("style")].into_iter().collect(); | ||
cmd.env("CARGO_TARGET_DIR", target_dir.as_path()); | ||
} | ||
|
||
fn ensure_success(mut cmd: std::process::Command) { | ||
println!("Running {:?}", cmd); | ||
match cmd.status() { | ||
Err(e) => { | ||
panic!("Could not spawn the command: {e}") | ||
} | ||
Ok(out) if !out.success() => panic!("exit code {:?}", out), | ||
Ok(_) => {} | ||
} | ||
} | ||
|
||
#[test] | ||
fn rustfmt() { | ||
let cargo = std::env::var_os("CARGO").unwrap_or(OsString::from("cargo")); | ||
let mut cmd = Command::new(cargo); | ||
cargo_env(&mut cmd); | ||
cmd.args(&["fmt", "--", "--check"]); | ||
ensure_success(cmd); | ||
} | ||
|
||
#[test] | ||
fn clippy() { | ||
let cargo = std::env::var_os("CARGO").unwrap_or(OsString::from("cargo")); | ||
let mut cmd = Command::new(cargo); | ||
cargo_env(&mut cmd); | ||
cmd.args(&["clippy", "--all-targets", "--all-features", "--"]); | ||
cmd.args(&[ | ||
"-Aclippy::all", | ||
"-Dclippy::clone_on_copy", | ||
"-Dclippy::correctness", | ||
"-Dclippy::derivable_impls", | ||
"-Dclippy::redundant_clone", | ||
"-Dclippy::suspicious", | ||
"-Dclippy::len_zero", | ||
]); | ||
ensure_success(cmd); | ||
} | ||
|
||
#[test] | ||
fn deny() { | ||
let cargo = std::env::var_os("CARGO").unwrap_or(OsString::from("cargo")); | ||
let mut cmd = Command::new(cargo); | ||
cargo_env(&mut cmd); | ||
cmd.args(&["deny", "--all-features", "check", "bans"]); | ||
ensure_success(cmd); | ||
} | ||
|
||
#[test] | ||
fn themis() { | ||
let cargo = std::env::var_os("CARGO").unwrap_or(OsString::from("cargo")); | ||
let mut cmd = Command::new(cargo); | ||
cargo_env(&mut cmd); | ||
cmd.args(&["run", "-p", "themis"]); | ||
ensure_success(cmd); | ||
} |