You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[test]ing. I'm trying to test things with I/O and can't get it work without relying on app.run():
Here's dirty PoC.
#[test]
fn test_loading_image() {
fn headless() -> PluginGroupBuilder {
let mut winit = WinitPlugin::<WakeUp>::default();
winit.run_on_any_thread = true;
DefaultPlugins
.set(RenderPlugin {
render_creation: WgpuSettings {
backends: None,
..default()
}
.into(),
..default()
})
.set(winit)
.disable::<AudioPlugin>()
}
let mut app = App::new();
app.add_plugins(headless());
#[derive(Resource)]
struct Timeout(Timer);
#[derive(Resource)]
struct Sample(Handle<Image>);
app.insert_resource(Timeout(Timer::from_seconds(1.0, TimerMode::Once)));
app.add_systems(Startup, |mut cmd: Commands, ass: Res<AssetServer>| {
cmd.insert_resource(Sample(ass.load("sample.png")));
});
fn tick_timeout(
mut t: ResMut<Timeout>,
time: Res<Time<Real>>,
sample: Res<Sample>,
asset_serer: Res<AssetServer>,
images: Res<Assets<Image>>,
) {
let load_state = asset_serer.load_state(&sample.0);
let from_load_state = matches!(load_state, bevy::asset::LoadState::Loaded);
let from_assets = images.get(&sample.0).is_some();
t.0.tick(time.delta());
if t.0.just_finished() {
println!(">>>>");
println!(">>>> finished timer with {from_load_state} {from_assets}");
println!(">>>>");
exit(1);
}
}
app.add_systems(Update, tick_timeout);
//app.run();
/*
* WORKS:
* >>>> finished timer with true true
*/
/* DOES NOT WORK
* >>>> finished timer with false false
*/
for _ in 0..1000000 {
app.update();
std::thread::sleep(Duration::from_secs_f32(0.01));
}
assert_eq!(1,2);
}
I expect test to fail(duh) with report that image is loaded.
If I do it with app.run(), it does -- both assets and asset_server report it's true that image was loaded.
However just using app.update() doesn't seems to load anything. What to do?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
#[test]ing. I'm trying to test things with I/O and can't get it work without relying on app.run():Here's dirty PoC.
I expect test to fail(duh) with report that image is loaded.
and asset_server report it's true that image was loaded.
If I do it with app.run(), it does -- both assets
However just using app.update() doesn't seems to load anything. What to do?
Beta Was this translation helpful? Give feedback.
All reactions