1//! Helper module which helps to determine amount of threads to be used
2//! during tests execution.
3use std::{env, num::NonZero, thread};
4
5pub fn get_concurrency() -> usize {
6 if let Ok(value) = env::var("RUST_TEST_THREADS") {
7 match value.parse::<NonZero<usize>>().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}
15