facett-core/tests/gpu_lane_is_installed.rs
//! **`lane::is_installed` answers through a real egui host** (needs `--features wgpu`).
//!
//! The registry half is proven without a device in `render::lane`'s unit tests and its
//! no-allocation promise in `tests/lane_is_installed_allocates_nothing.rs`. This file
//! proves the WIRING: the one install writer (`render::gpu::install_renderer`) raises
//! the flag for the renderer type it installed, and the graph-cloud lane's own gate
//! (`cloud_renderer_installed`) is that same flag — it used to be a private second
//! `AtomicBool`, and two flags for one fact is how they come to disagree.
//!
//! The flags are process-global and never lowered by an install, so each test uses a
//! renderer TYPE no other test in this binary installs.
//!
//! Run: `cargo test -p facett-core --features wgpu --test gpu_lane_is_installed`
#![cfg(feature = "wgpu")]
use facett_core::render::gpu::graphcloud::cloud::{
cloud_renderer_installed, install_cloud_renderer, CloudRenderer,
};
use facett_core::render::gpu::install_renderer;
use facett_core::render::lane;
/// A real `egui_wgpu::RenderState` — the object an eframe host hands its widgets —
/// with no window. Panics without an adapter (see `tests/gpu_pick_host.rs` for why that
/// is the right outcome).
fn render_state() -> egui_wgpu::RenderState {
let setup = egui_kittest::wgpu::default_wgpu_setup();
egui_kittest::wgpu::create_render_state(setup, Default::default())
}
/// A renderer that owns nothing — enough for the install lifecycle.
struct ProbeRenderer;
#[test]
fn install_renderer_raises_the_flag_of_the_type_it_installed() {
let _gpu = facett_core::render::gputurn::hold();
let rs = render_state();
let name = std::any::type_name::<ProbeRenderer>();
assert!(!lane::is_installed(name), "nothing installed it yet");
assert!(install_renderer(&rs, |_device, _format| ProbeRenderer), "fresh RenderState installs");
assert!(lane::is_installed(name), "the install writer must raise the flag");
assert!(
lane::lanes().iter().any(|l| l.name == name && l.installed),
"and the record the About box reads must agree with the cheap read",
);
assert!(!lane::is_installed("facett_core::NoSuchRenderer"), "only THAT type's flag rose");
assert!(!install_renderer(&rs, |_device, _format| ProbeRenderer), "second install is a no-op");
assert!(lane::is_installed(name), "…and leaves the flag up");
}
#[test]
fn the_cloud_gate_is_the_lane_registry_flag() {
let _gpu = facett_core::render::gputurn::hold();
let rs = render_state();
let name = std::any::type_name::<CloudRenderer>();
assert_eq!(
cloud_renderer_installed(),
lane::is_installed(name),
"before the install the two reads must already agree",
);
assert!(!cloud_renderer_installed(), "no host installed the cloud in this binary yet");
install_cloud_renderer(&rs);
assert!(cloud_renderer_installed(), "install_cloud_renderer must open the GPU fast path");
assert!(lane::is_installed(name), "…through the lane registry's flag");
assert!(
rs.renderer.read().callback_resources.get::<CloudRenderer>().is_some(),
"the flag is only honest if the renderer really sits in the RenderState",
);
}