Skip to content

Desktop tests: share one wgpu device (fixes a crash in parallel runs on Windows) - #35

Open
Skyfuller1303 wants to merge 3 commits into
itrycodinganditsbad:mainfrom
Skyfuller1303:desktop-test-wgpu
Open

Skyfuller1303 wants to merge 3 commits into
itrycodinganditsbad:mainfrom
Skyfuller1303:desktop-test-wgpu

Conversation

@Skyfuller1303

@Skyfuller1303 Skyfuller1303 commented Nov 6, 2026 •

Copy link
Copy Markdown

cargo test -p craft-cloud-desktop --lib crashes on Windows in most runs with 0xc0000005, STATUS_ACCESS_VIOLATION. It happens on main too: 4 of 5 parallel runs crashed there. With --no-capture the process dies after 42 to 44 of the 51 tests, without a test result line, so the crash comes in the middle of the run and not at exit. With --test-threads=1 it never happened.

Cause

Every UI test built its harness with .wgpu(), which creates a new wgpu instance and device (WARP, D3D12 on Windows) for each test. The tests run on parallel threads, so several D3D12 devices were created and dropped at the same time. Creating the device once makes the crash go away. I haven't debugged the access violation inside WARP itself.

Change

Test code only, in apps/craft-cloud-desktop/src/ui/tests.rs.

First version: shared_wgpu() creates the instance, adapter, device and queue once and every harness uses it. That was not enough on Windows. Creating, drawing with and dropping renderers on the shared device from several threads still corrupted the heap now and then: the DX12 shader blob reference counts in wgpu are not thread-safe (gfx-rs/wgpu#10547), and parallel WARP rendering has its own problems (emilk/egui#8772).

Current version (29b95db): rendering goes through a global lock. serialized() returns a renderer whose construction, handle_delta, render and Drop all run under one mutex (a poisoned lock is ignored), so only one test renders at a time. harness() uses .renderer(serialized()); shared_wgpu() stays. It costs about 8 % of the wall time of the desktop lib tests (about 29.3 s to 31.8 s for 431 tests on the larger branches). Once a wgpu release that contains gfx-rs/wgpu#10805 is used, the lock and Serialized can go and the tests can return to .wgpu_setup(shared_wgpu()).

There are no dependency or lock-file changes. Snapshots are unchanged. The Security page tests from #19 build their own harness; #34 (merged last) makes the matching change in them once this PR is in.

Testing (Windows)

  • Before the change: 5 parallel runs on main, 4 crashed. The pristine main still crashes (0xc0000005) in cargo test -p craft-cloud-desktop --lib.
  • With 29b95db: cargo fmt --all --check and cargo clippy --workspace --all-targets --locked -- -D warnings pass; cargo test -p craft-cloud-desktop --lib passed three times in a row (51 tests each, one run with RUST_TEST_THREADS=48). No snapshot file changed.
  • A full cargo test --workspace --locked on this head ran 1004 tests with none failing in the tests themselves. The command still exits non-zero here because the agent's live_documents test binary aborts with an out-of-memory error on branches based on main; that is Agent: build historical live snapshots without Loro's checkout (fixes #15) #16, unrelated to this PR.
  • Linux: the desktop lib tests also passed in WSL. CI covers Linux and macOS.

Every ui test built its harness with `.wgpu()`, which creates a fresh wgpu
instance and device (WARP on Windows) per test. The tests run on parallel
threads, and creating and dropping several D3D12 devices at the same time
crashed the test process with STATUS_ACCESS_VIOLATION (0xc0000005) in the
middle of the run, in most runs of `cargo test -p craft-cloud-desktop --lib`
on Windows. With `--test-threads=1` it never happened.

Create the instance, adapter, device and queue once, keep them in a
`OnceLock` (so no device is torn down while other threads render) and hand
them to each harness with `wgpu_setup(WgpuSetup::Existing(..))`. Every
harness still gets its own renderer. Snapshots are unchanged. Test code
only; this works on every backend kittest picks (lavapipe, WARP, Metal).
Other test modules of the app (such as a Security page test module in a
stacked pull request) build their own kittest harnesses. Make shared_wgpu()
visible to them, so all of the app's harnesses render on one device.
Skyfuller1303 added a commit to Skyfuller1303/craft-cloud that referenced this pull request Nov 7, 2026
Skyfuller1303 added a commit to Skyfuller1303/craft-cloud that referenced this pull request Nov 7, 2026
The Security page tests (from itrycodinganditsbad#19) built their kittest harness with
.wgpu(), a new wgpu device per test, which crashed the test process with
STATUS_ACCESS_VIOLATION when run in parallel on Windows, like the other UI
tests did before itrycodinganditsbad#35. Use the shared device from itrycodinganditsbad#35 here too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant