From be0a93271f18fe69b3a794b0b006b753a56156d7 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:04:41 +0100 Subject: [PATCH] test: retry ETXTBSY when horizon-server tests run a script they just wrote engine::tests::the_check_runs_the_program failed on CI (verify of #2215) with "can't start: Text file busy (os error 26)". The test writes a shell script and runs it at once; when another test thread forks to spawn a process while the script's write handle is open, the child keeps that handle until it execs, and running the script meanwhile fails with ETXTBSY on Linux. The two engine tests that do this now retry that one error (up to 50 times, 20 ms apart). Test-only change. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-server/src/engine.rs | 42 ++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/crates/horizon-server/src/engine.rs b/crates/horizon-server/src/engine.rs index fd7c86321..ce288fdff 100644 --- a/crates/horizon-server/src/engine.rs +++ b/crates/horizon-server/src/engine.rs @@ -315,18 +315,42 @@ mod tests { .unwrap(); std::fs::set_permissions(&game, std::fs::Permissions::from_mode(0o755)).unwrap(); std::fs::write(server.join("server.toml"), "").unwrap(); - let status = spawn( - &std::path::absolute(&game).unwrap(), - &root.join("res"), - &server, - ) - .unwrap() - .wait(); + // ETXTBSY: see `check_written`. + let mut tries = 0; + let status = loop { + match spawn( + &std::path::absolute(&game).unwrap(), + &root.join("res"), + &server, + ) { + Err(e) if e.raw_os_error() == Some(26) && tries < 50 => { + tries += 1; + std::thread::sleep(std::time::Duration::from_millis(20)); + } + child => break child.unwrap().wait(), + } + }; std::fs::remove_dir_all(&root).unwrap(); let status = status.unwrap(); assert!(status.success(), "{status}"); } + /// `check_starts` on a script this test process just wrote. Another test's spawn can fork while the + /// script's write handle is still open, and its child keeps that handle until it execs: running the + /// script meanwhile fails with ETXTBSY (Linux), so that one error is retried. + #[cfg(unix)] + fn check_written(program: &Path) -> Result<(), String> { + for _ in 0..50 { + match check_starts(program) { + Err(e) if e.contains("Text file busy") => { + std::thread::sleep(std::time::Duration::from_millis(20)) + } + other => return other, + } + } + check_starts(program) + } + #[cfg(unix)] #[test] fn the_check_runs_the_program() { @@ -340,10 +364,10 @@ mod tests { std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o755)).unwrap(); path }; - assert_eq!(check_starts(&script("starts", "exit 0")), Ok(())); + assert_eq!(check_written(&script("starts", "exit 0")), Ok(())); let fails = script("fails", "echo 'no luck' >&2; exit 3"); assert_eq!( - check_starts(&fails), + check_written(&fails), Err(format!( "the game ({}) can't start (exit status 3): no luck", fails.display()