diff --git a/control-plane/src/embedded_engine.rs b/control-plane/src/embedded_engine.rs index 05c0cb30..14c6b91e 100644 --- a/control-plane/src/embedded_engine.rs +++ b/control-plane/src/embedded_engine.rs @@ -118,7 +118,7 @@ mod tests { #[cfg(target_os = "linux")] #[test] fn sealed_payload_is_exact_immutable_and_removed_on_drop() { - use std::io::Write; + use std::{io::Write, os::unix::fs::MetadataExt}; let engine = materialize(b"immutable fixture bytes").unwrap(); let path = engine.executable.clone(); assert_eq!(std::fs::read(&path).unwrap(), b"immutable fixture bytes"); @@ -126,8 +126,19 @@ mod tests { assert!(other.write_all(b"x").is_err()); assert!(other.set_len(0).is_err()); assert!(other.set_len(100).is_err()); - drop(other); + // Keep a witness open so this inode cannot be recycled during the check. + // Parallel tests can reuse the original descriptor number after Drop. + let original = other.metadata().unwrap(); + assert_eq!(std::fs::metadata(&path).unwrap().ino(), original.ino()); drop(engine); - assert!(!path.exists()); + match std::fs::metadata(&path) { + Ok(current) => assert_ne!( + (current.dev(), current.ino()), + (original.dev(), original.ino()), + "original descriptor still refers to the payload after Drop" + ), + Err(error) => assert_eq!(error.kind(), std::io::ErrorKind::NotFound), + } + drop(other); } }