diff --git a/rust/loki-rs/tests/dictate.rs b/rust/loki-rs/tests/dictate.rs index 49bfe83..566483f 100644 --- a/rust/loki-rs/tests/dictate.rs +++ b/rust/loki-rs/tests/dictate.rs @@ -10,7 +10,6 @@ mod common; use std::convert::Infallible; -use std::io::Write; use std::net::SocketAddr; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; @@ -467,16 +466,19 @@ while True: c.close() "#; +/// Écrit par un `sh` à part : si ce process tenait lui-même le fichier ouvert +/// en écriture, un `fork` lancé au même moment par un test voisin en +/// hériterait, et l'`exec` du script échouerait sur ETXTBSY. fn script(dir: &Path, name: &str, body: &str) -> String { let p = dir.join(name); - let mut f = std::fs::File::create(&p).unwrap(); - f.write_all(body.as_bytes()).unwrap(); - drop(f); - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); - } + let ok = std::process::Command::new("sh") + .args(["-c", r#"printf '%s' "$1" > "$2" && chmod 755 "$2""#, "sh"]) + .arg(body) + .arg(&p) + .status() + .unwrap() + .success(); + assert!(ok, "script non écrit"); p.to_string_lossy().into_owned() } diff --git a/rust/loki-rs/tests/engine.rs b/rust/loki-rs/tests/engine.rs index c25c11e..77e608d 100644 --- a/rust/loki-rs/tests/engine.rs +++ b/rust/loki-rs/tests/engine.rs @@ -9,10 +9,22 @@ use std::time::Duration; /// Faux binaire Go : `serve` lance un « llama-server » dans sa session et un /// « moteur Strata » qui prend SA PROPRE session (comme le vrai), puis attend. +/// +/// Écrit par un `sh` à part : si ce process tenait lui-même le fichier ouvert +/// en écriture, un `fork` lancé au même moment par un test voisin (les tests +/// tournent en parallèle) en hériterait, et l'`exec` du script échouerait sur +/// ETXTBSY (« Text file busy »). fn faux_go(dir: &Path, corps: &str) -> PathBuf { let p = dir.join("faux-loki"); - std::fs::write(&p, format!("#!/bin/sh\n{corps}\n")).unwrap(); - std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); + let ok = std::process::Command::new("sh") + .args(["-c", r#"printf '%s' "$1" > "$2" && chmod 755 "$2""#, "sh"]) + .arg(format!("#!/bin/sh\n{corps}\n")) + .arg(&p) + .status() + .unwrap() + .success(); + assert!(ok, "faux binaire non écrit"); + assert!(std::fs::metadata(&p).unwrap().permissions().mode() & 0o111 != 0); p }