Skip to content

Make GatedReader a test-only symbol, and allow all bevy_asset tests to all run single threaded. #18473

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.17.0-dev", default-featu
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
notify-debouncer-full = { version = "0.5.0", default-features = false, optional = true }

[dev-dependencies]
async-channel = "2"

[lints]
workspace = true

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_asset/src/io/gated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::{boxed::Box, sync::Arc};
use async_channel::{Receiver, Sender};
use bevy_platform::collections::HashMap;
use crossbeam_channel::{Receiver, Sender};
use parking_lot::RwLock;
use std::path::Path;

Expand Down Expand Up @@ -35,8 +35,8 @@ impl GateOpener {
let mut gates = self.gates.write();
let gates = gates
.entry_ref(path.as_ref())
.or_insert_with(crossbeam_channel::unbounded);
gates.0.send(()).unwrap();
.or_insert_with(async_channel::unbounded);
gates.0.send_blocking(()).unwrap();
}
}

Expand All @@ -61,10 +61,10 @@ impl<R: AssetReader> AssetReader for GatedReader<R> {
let mut gates = self.gates.write();
let gates = gates
.entry_ref(path.as_ref())
.or_insert_with(crossbeam_channel::unbounded);
.or_insert_with(async_channel::unbounded);
gates.1.clone()
};
receiver.recv().unwrap();
receiver.recv().await.unwrap();
let result = self.reader.read(path).await?;
Ok(result)
}
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_asset/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ pub mod android;
pub mod embedded;
#[cfg(not(target_arch = "wasm32"))]
pub mod file;
pub mod gated;
pub mod memory;
pub mod processor_gated;
#[cfg(target_arch = "wasm32")]
pub mod wasm;

#[cfg(test)]
pub mod gated;

mod source;

pub use futures_lite::AsyncWriteExt;
Expand Down
20 changes: 0 additions & 20 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,6 @@ mod tests {

#[test]
fn load_dependencies() {
// The particular usage of GatedReader in this test will cause deadlocking if running single-threaded
#[cfg(not(feature = "multi_threaded"))]
panic!("This test requires the \"multi_threaded\" feature, otherwise it will deadlock.\ncargo test --package bevy_asset --features multi_threaded");

let dir = Dir::default();

let a_path = "a.cool.ron";
Expand Down Expand Up @@ -1202,10 +1198,6 @@ mod tests {

#[test]
fn failure_load_states() {
// The particular usage of GatedReader in this test will cause deadlocking if running single-threaded
#[cfg(not(feature = "multi_threaded"))]
panic!("This test requires the \"multi_threaded\" feature, otherwise it will deadlock.\ncargo test --package bevy_asset --features multi_threaded");

let dir = Dir::default();

let a_path = "a.cool.ron";
Expand Down Expand Up @@ -1335,10 +1327,6 @@ mod tests {

#[test]
fn dependency_load_states() {
// The particular usage of GatedReader in this test will cause deadlocking if running single-threaded
#[cfg(not(feature = "multi_threaded"))]
panic!("This test requires the \"multi_threaded\" feature, otherwise it will deadlock.\ncargo test --package bevy_asset --features multi_threaded");

let a_path = "a.cool.ron";
let a_ron = r#"
(
Expand Down Expand Up @@ -1474,10 +1462,6 @@ mod tests {

#[test]
fn manual_asset_management() {
// The particular usage of GatedReader in this test will cause deadlocking if running single-threaded
#[cfg(not(feature = "multi_threaded"))]
panic!("This test requires the \"multi_threaded\" feature, otherwise it will deadlock.\ncargo test --package bevy_asset --features multi_threaded");

let dir = Dir::default();
let dep_path = "dep.cool.ron";

Expand Down Expand Up @@ -1575,10 +1559,6 @@ mod tests {

#[test]
fn load_folder() {
// The particular usage of GatedReader in this test will cause deadlocking if running single-threaded
#[cfg(not(feature = "multi_threaded"))]
panic!("This test requires the \"multi_threaded\" feature, otherwise it will deadlock.\ncargo test --package bevy_asset --features multi_threaded");

let dir = Dir::default();

let a_path = "text/a.cool.ron";
Expand Down