Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(keyring): reserve two timestamps in quarantine collision test

Steven Enamakelf7306a77ccd6
diff --git a/crates/openhuman-core/src/security/keyring/file_store_tests.rs b/crates/openhuman-core/src/security/keyring/file_store_tests.rs
index e39cc4fe0e..8654e18630 100644
--- a/crates/openhuman-core/src/security/keyring/file_store_tests.rs
+++ b/crates/openhuman-core/src/security/keyring/file_store_tests.rs
@@ -204,12 +204,20 @@ fn quarantine_never_replaces_a_name_another_process_reserved() {
let path = dir.path().join("secrets.enc");
std::fs::write(&path, b"mine").unwrap();
// Another process already holds every name this second could pick first.
+ // Reserve this second and the next, so a clock tick cannot dodge the test.
let stamp = chrono::Utc::now().timestamp();
- let taken = path.with_extension(format!("enc.corrupt.{stamp}"));
- std::fs::write(&taken, b"theirs").unwrap();
+ let taken: Vec<_> = [stamp, stamp + 1]
+ .iter()
+ .map(|s| path.with_extension(format!("enc.corrupt.{s}")))
+ .collect();
+ for t in &taken {
+ std::fs::write(t, b"theirs").unwrap();
+ }
let moved = quarantine_corrupt(&path, "enc").expect("moved aside");
- assert_ne!(moved, taken);
+ assert!(!taken.contains(&moved), "{moved:?} was already taken");
assert!(!path.exists(), "the corrupt original is gone");
assert_eq!(std::fs::read(&moved).unwrap(), b"mine");
- assert_eq!(std::fs::read(&taken).unwrap(), b"theirs");
+ for t in &taken {
+ assert_eq!(std::fs::read(t).unwrap(), b"theirs");
+ }
}