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

make concurrency helper more pleasant to read #78065

Merged
merged 1 commit into from
Nov 8, 2020
Merged
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
18 changes: 7 additions & 11 deletions library/test/src/helpers/concurrency.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
//! Helper module which helps to determine amount of threads to be used
//! during tests execution.
use std::env;
use std::thread;
use std::{env, num::NonZeroUsize, thread};

#[allow(deprecated)]
pub fn get_concurrency() -> usize {
match env::var("RUST_TEST_THREADS") {
Ok(s) => {
let opt_n: Option<usize> = s.parse().ok();
match opt_n {
Some(n) if n > 0 => n,
_ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s),
}
if let Ok(value) = env::var("RUST_TEST_THREADS") {
m-ou-se marked this conversation as resolved.
Show resolved Hide resolved
match value.parse::<NonZeroUsize>().ok() {
Some(n) => n.get(),
_ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", value),
}
Err(..) => thread::available_concurrency().map(|n| n.get()).unwrap_or(1),
} else {
thread::available_concurrency().map(|n| n.get()).unwrap_or(1)
}
}