From 79c11bf35c74c9ccb8d416d13a9e5288cab4756f Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Fri, 13 Nov 2026 09:11:42 -0500 Subject: [PATCH] test: wait until the copied binary can be run On Linux a test on another thread can start a process while the copy is still open for writing, and running it then fails with "Text file busy". This failed CI on the 0.3.0 release commit and passed on a rerun. Co-Authored-By: Claude Fable 5.2 --- tests/update.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/update.rs b/tests/update.rs index f196ef0..d314ba4 100644 --- a/tests/update.rs +++ b/tests/update.rs @@ -252,9 +252,25 @@ mod install { fn copy_of_binary(dir: &Path) -> Result> { let path = dir.join("firebird-cli"); std::fs::copy(assert_cmd::cargo::cargo_bin("firebird-cli"), &path)?; + wait_until_runnable(&path)?; Ok(path) } + /// A test on another thread can start a process while this copy is still + /// open for writing. That process holds the copy open until it execs, and + /// Linux refuses to run a file open for writing ("Text file busy"). + fn wait_until_runnable(path: &Path) -> std::io::Result<()> { + for _ in 0..200 { + match std::process::Command::new(path).arg("--version").output() { + Err(e) if e.kind() == std::io::ErrorKind::ExecutableFileBusy => { + std::thread::sleep(std::time::Duration::from_millis(10)); + } + other => return other.map(|_| ()), + } + } + Ok(()) + } + /// The archive `release.yml` would publish, holding a script that /// answers `--version` as the new release. fn archive(target: &str) -> Result, Box> {