From 902796ffb2869e88b81509959620e127c3da729b Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Sat, 7 Nov 2026 07:35:54 +0000 Subject: [PATCH] test(cli): copy the forwarder in a child process so parallel tests cannot hold it busy --- crates/sqlbuild-cli/tests/launcher/helpers.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/sqlbuild-cli/tests/launcher/helpers.rs b/crates/sqlbuild-cli/tests/launcher/helpers.rs index dd34f6728..3e132ca8d 100644 --- a/crates/sqlbuild-cli/tests/launcher/helpers.rs +++ b/crates/sqlbuild-cli/tests/launcher/helpers.rs @@ -108,10 +108,26 @@ pub(crate) fn sqb_file() -> String { /// A copy of the real `sqlbuild` forwarder, alone in `directory`; a copy works across volumes. pub(crate) fn forwarder_in(directory: &Path) -> PathBuf { let forwarder = directory.join(format!("sqlbuild{}", std::env::consts::EXE_SUFFIX)); - std::fs::copy(env!("CARGO_BIN_EXE_sqlbuild"), &forwarder).expect("copy the forwarder"); + copy_executable(Path::new(env!("CARGO_BIN_EXE_sqlbuild")), &forwarder); forwarder } +/// Copies in a child, so tests forking in parallel never inherit a write handle (ETXTBSY). +#[cfg(unix)] +fn copy_executable(source: &Path, destination: &Path) { + let status = Command::new("cp") + .arg(source) + .arg(destination) + .status() + .expect("run cp"); + assert!(status.success(), "copy the forwarder: {status:?}"); +} + +#[cfg(windows)] +fn copy_executable(source: &Path, destination: &Path) { + std::fs::copy(source, destination).expect("copy the forwarder"); +} + /// The real forwarder with a fake `sqb` beside it that reports what it received. pub(crate) fn forwarder_with_fake_sqb(directory: &Path) -> PathBuf { compile(FAKE_SQB, directory, "sqb");