Skip to content

Commit ca9a17a

Browse files
authored
test(cli): copy the forwarder in a child process so parallel tests cannot hold it busy (#1339)
1 parent b904532 commit ca9a17a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎crates/sqlbuild-cli/tests/launcher/helpers.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,26 @@ pub(crate) fn sqb_file() -> String {
108108
/// A copy of the real `sqlbuild` forwarder, alone in `directory`; a copy works across volumes.
109109
pub(crate) fn forwarder_in(directory: &Path) -> PathBuf {
110110
let forwarder = directory.join(format!("sqlbuild{}", std::env::consts::EXE_SUFFIX));
111-
std::fs::copy(env!("CARGO_BIN_EXE_sqlbuild"), &forwarder).expect("copy the forwarder");
111+
copy_executable(Path::new(env!("CARGO_BIN_EXE_sqlbuild")), &forwarder);
112112
forwarder
113113
}
114114

115+
/// Copies in a child, so tests forking in parallel never inherit a write handle (ETXTBSY).
116+
#[cfg(unix)]
117+
fn copy_executable(source: &Path, destination: &Path) {
118+
let status = Command::new("cp")
119+
.arg(source)
120+
.arg(destination)
121+
.status()
122+
.expect("run cp");
123+
assert!(status.success(), "copy the forwarder: {status:?}");
124+
}
125+
126+
#[cfg(windows)]
127+
fn copy_executable(source: &Path, destination: &Path) {
128+
std::fs::copy(source, destination).expect("copy the forwarder");
129+
}
130+
115131
/// The real forwarder with a fake `sqb` beside it that reports what it received.
116132
pub(crate) fn forwarder_with_fake_sqb(directory: &Path) -> PathBuf {
117133
compile(FAKE_SQB, directory, "sqb");

0 commit comments

Comments
 (0)