Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when not using cargo-nextest #3293

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non
- Use cargo 1.64 workspace inheritance feature. By @jinleili in [#3107](https://github.com/gfx-rs/wgpu/pull/3107)
- Move `ResourceMetadata` into its own module. By @jimblandy in [#3213](https://github.com/gfx-rs/wgpu/pull/3213)
- Add WebAssembly testing infrastructure. By @haraldreingruber in [#3238](https://github.com/gfx-rs/wgpu/pull/3238)
- Error message when you forget to use cargo-nextest. By @cwfitzgerald in [#]()

#### Vulkan

Expand Down
43 changes: 43 additions & 0 deletions wgpu/tests/common/isolation.rs
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);
}
}
4 changes: 4 additions & 0 deletions wgpu/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use wgpu::{Adapter, Device, DownlevelFlags, Instance, Queue, Surface};
use wgt::{Backends, DeviceDescriptor, DownlevelCapabilities, Features, Limits};

pub mod image;
mod isolation;

const CANVAS_ID: &str = "test-canvas";

Expand Down Expand Up @@ -167,13 +168,16 @@ impl TestParameters {
self
}
}

pub fn initialize_test(parameters: TestParameters, test_function: impl FnOnce(TestingContext)) {
// We don't actually care if it fails
#[cfg(not(target_arch = "wasm32"))]
let _ = env_logger::try_init();
#[cfg(target_arch = "wasm32")]
let _ = console_log::init_with_level(log::Level::Info);

let _test_guard = isolation::OneTestPerProcessGuard::new();

let (adapter, _) = initialize_adapter();

let adapter_info = adapter.get_info();
Expand Down