blob: eb211157371b55b532c5888c9b93fc9856b1f9fb [file] [log] [blame]
//! Helper module which helps to determine amount of threads to be used
//! during tests execution.
use std::{env, num::NonZeroUsize, thread};
pub fn get_concurrency() -> usize {
if let Ok(value) = env::var("RUST_TEST_THREADS") {
match value.parse::<NonZeroUsize>().ok() {
Some(n) => n.get(),
_ => panic!("RUST_TEST_THREADS is `{value}`, should be a positive integer."),
}
} else {
thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
}
}