1 //! Helper module which helps to determine amount of threads to be used
2 //! during tests execution.
3 use std::{env, num::NonZeroUsize, thread};
5 pub fn get_concurrency() -> usize {
6 if let Ok(value) = env::var("RUST_TEST_THREADS") {
7 match value.parse::<NonZeroUsize>().ok() {
9 _ => panic!("RUST_TEST_THREADS is `{value}`, should be a positive integer."),
12 thread::available_parallelism().map(|n| n.get()).unwrap_or(1)