1 | use std::collections::HashSet; |
2 | |
3 | use rayon::prelude::*; |
4 | use rayon::*; |
5 | |
6 | #[test] |
7 | #[cfg_attr (any(target_os = "emscripten" , target_family = "wasm" ), ignore)] |
8 | fn named_threads() { |
9 | ThreadPoolBuilder::new() |
10 | .thread_name(|i| format!("hello-name-test-{}" , i)) |
11 | .build_global() |
12 | .unwrap(); |
13 | |
14 | const N: usize = 10000; |
15 | |
16 | let thread_names = (0..N) |
17 | .into_par_iter() |
18 | .flat_map(|_| ::std::thread::current().name().map(str::to_owned)) |
19 | .collect::<HashSet<String>>(); |
20 | |
21 | let all_contains_name = thread_names |
22 | .iter() |
23 | .all(|name| name.starts_with("hello-name-test-" )); |
24 | assert!(all_contains_name); |
25 | } |
26 | |