]> git.lizzy.rs Git - rust.git/blob - library/test/src/helpers/concurrency.rs
Rollup merge of #89869 - kpreid:from-doc, r=yaahc
[rust.git] / library / test / src / helpers / concurrency.rs
1 //! Helper module which helps to determine amount of threads to be used
2 //! during tests execution.
3 use std::{env, num::NonZeroUsize, thread};
4
5 pub fn get_concurrency() -> usize {
6     if let Ok(value) = env::var("RUST_TEST_THREADS") {
7         match value.parse::<NonZeroUsize>().ok() {
8             Some(n) => n.get(),
9             _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", value),
10         }
11     } else {
12         thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
13     }
14 }