forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#78065 - tshepang:nits, r=dtolnay
make concurrency helper more pleasant to read
- Loading branch information
Showing
1 changed file
with
7 additions
and
11 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,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") { | ||
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) | ||
} | ||
} |