summaryrefslogtreecommitdiffstats
path: root/library/test/src/helpers/concurrency.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/test/src/helpers/concurrency.rs')
-rw-r--r--library/test/src/helpers/concurrency.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs
new file mode 100644
index 000000000..eb2111573
--- /dev/null
+++ b/library/test/src/helpers/concurrency.rs
@@ -0,0 +1,14 @@
+//! Helper module which helps to determine amount of threads to be used
+//! during tests execution.
+use std::{env, num::NonZeroUsize, thread};
+
+pub fn get_concurrency() -> usize {
+ if let Ok(value) = env::var("RUST_TEST_THREADS") {
+ match value.parse::<NonZeroUsize>().ok() {
+ Some(n) => n.get(),
+ _ => panic!("RUST_TEST_THREADS is `{value}`, should be a positive integer."),
+ }
+ } else {
+ thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
+ }
+}