]> git.lizzy.rs Git - rust.git/blob - library/test/src/helpers/concurrency.rs
Add std::thread::available_concurrency
[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;
4 use std::thread;
5
6 #[allow(deprecated)]
7 pub fn get_concurrency() -> usize {
8     match env::var("RUST_TEST_THREADS") {
9         Ok(s) => {
10             let opt_n: Option<usize> = s.parse().ok();
11             match opt_n {
12                 Some(n) if n > 0 => n,
13                 _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s),
14             }
15         }
16         Err(..) => thread::available_concurrency().map(|n| n.get()).unwrap_or(1),
17     }
18 }