1
/// Constructs a logger for tests. This logger will not print anything to the console, but will instead write to a buffer.
2
9596
pub fn test_logger() {
3
9596
    if cfg!(not(feature = "merc_miri")) {
4
9596
        // Ignore double initialisations in tests since tests are ran in parallel.
5
9596
        let _ = env_logger::builder().is_test(true).try_init();
6
9596
    }
7
9596
}
8

            
9
1
pub fn test_threads<C, F, G>(num_threads: usize, init_function: G, test_function: F)
10
1
where
11
1
    C: Send + 'static,
12
1
    F: Fn(&mut C) + Copy + Send + Sync + 'static,
13
1
    G: Fn() -> C,
14
{
15
1
    test_logger();
16

            
17
1
    let mut threads = vec![];
18

            
19
1
    for _ in 0..num_threads {
20
20
        let mut init = init_function();
21
20
        threads.push(std::thread::spawn(move || {
22
20
            test_function(&mut init);
23
20
        }));
24
    }
25

            
26
20
    for thread in threads {
27
20
        let _ = thread.join();
28
20
    }
29
1
}