test/helpers/
concurrency.rs

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