Skip to content

flake(test): Windows emulator tests spawn 'powershell' by basename, fail under concurrent load #95

@zackees

Description

@zackees

Symptom

Under uv run cargo test --workspace on Windows, handlers::emulator::tests::* tests that use test_process_command() occasionally fail with:

```
thread 'handlers::emulator::tests::run_avr8js_headless_captures_stdout' panicked at crates\fbuild-daemon\src\handlers\emulator.rs:2523:10:
called `Result::unwrap()` on an `Err` value: DeployFailed("failed to launch QEMU at powershell: program not found")
```

  • Observed at least twice this session (different tests each time: once is_qemu_supported_esp32_mcu_rejects_unsupported, once run_avr8js_headless_captures_stdout).
  • Always passes when re-run in isolation or with a smaller test subset.
  • Specifically triggers under full-workspace concurrent load where many tests spawn subprocesses in parallel.

Root cause

crates/fbuild-daemon/src/handlers/emulator.rs:2291test_process_command() returns PathBuf::from(\"powershell\") on Windows, a bare basename. Command::spawn() then relies on Windows executable-search semantics (SearchPathW plus Rust's own resolution wrapper) to find powershell.exe. Under concurrent load — many tests creating/deleting tempdirs, changing process state — this resolution occasionally fails and CreateProcessW returns ERROR_FILE_NOT_FOUND ("program not found").

Fix

Use an absolute path to PowerShell in the test harness. %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe exists on every Windows install since Vista and is not subject to PATH races.

```rust
#[cfg(windows)]
{
let system_root = std::env::var("SystemRoot").unwrap_or_else(|_| "C:\Windows".to_string());
let exe = PathBuf::from(system_root).join(r"System32\WindowsPowerShell\v1.0\powershell.exe");
(exe, vec![ /* unchanged args */ ])
}
```

Acceptance

  • Run uv run cargo test --workspace 5× consecutively on Windows without flakes in handlers::emulator::tests.
  • Test still passes on a stripped-PATH environment.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions