]> git.lizzy.rs Git - rust.git/blob - library/test/src/helpers/concurrency.rs
Auto merge of #102418 - citrus-it:illumos-strip-debug, r=nagisa
[rust.git] / library / test / src / helpers / concurrency.rs
1 //! Helper module which helps to determine amount of threads to be used
2 //! during tests execution.
3 use std::{env, num::NonZeroUsize, thread};
4
5 pub fn get_concurrency() -> usize {
6     if let Ok(value) = env::var("RUST_TEST_THREADS") {
7         match value.parse::<NonZeroUsize>().ok() {
8             Some(n) => n.get(),
9             _ => panic!("RUST_TEST_THREADS is `{value}`, should be a positive integer."),
10         }
11     } else {
12         thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
13     }
14 }