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