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