1use std::sync::atomic::{AtomicBool, Ordering};
2
3static TEST_ACTIVE_IN_PROCESS: AtomicBool = AtomicBool::new(false);
5
6const OTHER_TEST_IN_PROGRESS_ERROR: &str = "TEST ISOLATION ERROR:
7
8wgpu's test harness requires that no more than one test is running per process.
9
10The best way to facilitate this is by using cargo-nextest which runs each test in its own process
11and has a very good testing UI:
12
13cargo install cargo-nextest
14cargo nextest run
15
16Alternatively, you can run tests in single threaded mode (much slower).
17
18cargo test -- --test-threads=1
19
20Calling std::process::abort()...
21";
22
23pub struct OneTestPerProcessGuard(());
26
27impl OneTestPerProcessGuard {
28 pub fn new() -> Self {
29 let other_tests_in_flight = TEST_ACTIVE_IN_PROCESS.swap(true, Ordering::SeqCst);
30
31 if other_tests_in_flight && !cfg!(target_arch = "wasm32") {
34 log::error!("{OTHER_TEST_IN_PROGRESS_ERROR}");
35 std::process::abort();
37 }
38 OneTestPerProcessGuard(())
39 }
40}
41
42impl Drop for OneTestPerProcessGuard {
43 fn drop(&mut self) {
44 TEST_ACTIVE_IN_PROCESS.store(false, Ordering::SeqCst);
45 }
46}