-
Notifications
You must be signed in to change notification settings - Fork 953
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error when not using cargo-nextest (#3293)
Closes #3285
- Loading branch information
1 parent
f0f700c
commit 2480eff
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
/// True if a test is in progress somewhere in the process, false otherwise. | ||
static TEST_ACTIVE_IN_PROCESS: AtomicBool = AtomicBool::new(false); | ||
|
||
const OTHER_TEST_IN_PROGRESS_ERROR: &str = "TEST ISOLATION ERROR: | ||
wgpu's test harness requires that no more than one test is running per process. | ||
The best way to facilitate this is by using cargo-nextest which runs each test in its own process | ||
and has a very good testing UI: | ||
cargo install cargo-nextest | ||
cargo nextest run | ||
Alternatively, you can run tests in single threaded mode (much slower). | ||
cargo test -- --test-threads=1 | ||
Calling std::process::abort()... | ||
"; | ||
|
||
/// When this guard is active, enforces that there is only a single test running in the process | ||
/// at any one time. If there are multiple processes, creating the guard hard terminates the process. | ||
pub struct OneTestPerProcessGuard(()); | ||
|
||
impl OneTestPerProcessGuard { | ||
pub fn new() -> Self { | ||
let other_tests_in_flight = TEST_ACTIVE_IN_PROCESS.swap(true, Ordering::SeqCst); | ||
if other_tests_in_flight { | ||
log::error!("{}", OTHER_TEST_IN_PROGRESS_ERROR); | ||
// Hard exit to call attention to the error | ||
std::process::abort(); | ||
} | ||
OneTestPerProcessGuard(()) | ||
} | ||
} | ||
|
||
impl Drop for OneTestPerProcessGuard { | ||
fn drop(&mut self) { | ||
TEST_ACTIVE_IN_PROCESS.store(false, Ordering::SeqCst); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters