Skip to content
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

feat(test): add --parallel flag, soft deprecate --jobs #15259

Merged
merged 7 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
31 changes: 23 additions & 8 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,9 @@ static ENV_VARIABLES_HELP: &str = r#"ENVIRONMENT VARIABLES:
DENO_NO_PROMPT Set to disable permission prompts on access
(alternative to passing --no-prompt on invocation)
DENO_WEBGPU_TRACE Directory to use for wgpu traces
DENO_JOBS Number of parallel workers used for test subcommand.
Defaults to number of available CPUs when used with
--jobs flag and no value is provided.
Defaults to 1 when --jobs flag is not used.
DENO_JOBS Number of parallel workers used for the --parallel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about renaming this, but DENO_MAX_PARALLELISM is long. Additionally, cargo uses CARGO_JOBS for this env variable, so I think it makes sense? We can also reuse this env var for deno fmt and lint in the future. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me 👍

flag with the test subcommand. Defaults to number
of available CPUs.
HTTP_PROXY Proxy address for HTTP requests
(module downloads, fetch)
HTTPS_PROXY Proxy address for HTTPS requests
Expand Down Expand Up @@ -1548,6 +1547,13 @@ fn test_subcommand<'a>() -> Command<'a> {
.conflicts_with("inspect-brk")
.help("UNSTABLE: Collect coverage profile data into DIR"),
)
.arg(
Arg::new("parallel")
.long("parallel")
.help("Runs the tests in parallel. Parallelism defaults to the number of available CPUs or the value in the DENO_JOBS environment variable.")
dsherret marked this conversation as resolved.
Show resolved Hide resolved
.conflicts_with("jobs")
.takes_value(false)
)
.arg(
Arg::new("jobs")
.short('j')
Expand Down Expand Up @@ -2667,17 +2673,26 @@ fn test_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
}
}

let concurrent_jobs = if matches.is_present("jobs") {
if let Some(value) = matches.value_of("jobs") {
value.parse().unwrap()
} else if let Ok(value) = env::var("DENO_JOBS") {
let concurrent_jobs = if matches.is_present("parallel") {
if let Ok(value) = env::var("DENO_JOBS") {
value
.parse::<NonZeroUsize>()
.unwrap_or(NonZeroUsize::new(1).unwrap())
} else {
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1).unwrap())
}
} else if matches.is_present("jobs") {
println!(
"{}",
crate::colors::yellow("Warning: --jobs flag is deprecated. Use the --parallel flag with possibly the 'DENO_JOBS' environment variable."),
);
if let Some(value) = matches.value_of("jobs") {
value.parse().unwrap()
} else {
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1).unwrap())
}
} else {
NonZeroUsize::new(1).unwrap()
};
Expand Down
21 changes: 10 additions & 11 deletions cli/tests/integration/test_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,29 @@ itest!(test_with_malformed_config {
output: "test/collect_with_malformed_config.out",
});

itest!(jobs_flag {
args: "test test/short-pass.ts --jobs",
itest!(parallel_flag {
args: "test test/short-pass.ts --parallel",
exit_code: 0,
output: "test/short-pass.out",
});

itest!(jobs_flag_with_numeric_value {
args: "test test/short-pass.ts --jobs=2",
itest!(parallel_flag_with_env_variable {
args: "test test/short-pass.ts --parallel",
envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())],
exit_code: 0,
output: "test/short-pass-jobs-flag-with-numeric-value.out",
output: "test/short-pass.out",
});

itest!(jobs_flag_with_env_variable {
itest!(jobs_flag {
args: "test test/short-pass.ts --jobs",
envs: vec![("DENO_JOBS".to_owned(), "2".to_owned())],
exit_code: 0,
output: "test/short-pass.out",
output: "test/short-pass-jobs-flag-warning.out",
});

itest!(jobs_flag_with_numeric_value_and_env_var {
itest!(jobs_flag_with_numeric_value {
args: "test test/short-pass.ts --jobs=2",
envs: vec![("DENO_JOBS".to_owned(), "3".to_owned())],
exit_code: 0,
output: "test/short-pass-jobs-flag-with-numeric-value.out",
output: "test/short-pass-jobs-flag-warning.out",
});

itest!(load_unload {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Warning: --jobs flag is deprecated. Use the --parallel flag with possibly the 'DENO_JOBS' environment variable.
Check [WILDCARD]/test/short-pass.ts
running 1 test from ./test/short-pass.ts
test ... ok ([WILDCARD])
Expand Down