Skip to content

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

chore: files changed crates/openhuman-core/src/storage/lease_documents_tests.rs,crates/openhuman-cor

Steven Enamakel77ccac56d7d2
diff --git a/crates/openhuman-core/src/storage/lease_documents_tests.rs b/crates/openhuman-core/src/storage/lease_documents_tests.rs
index 5b77bc1c28..9334cd277b 100644
--- a/crates/openhuman-core/src/storage/lease_documents_tests.rs
+++ b/crates/openhuman-core/src/storage/lease_documents_tests.rs
@@ -131,57 +131,6 @@ async fn keys_are_independent() {
assert!(a.holder("three").await.unwrap().is_none());
}
-/// Real threads, each its own runtime and node, race for one key on one
-/// backend opened by URL: exactly one wins and the rest see it.
-#[cfg(feature = "storage-sqlite")]
-fn race_on(url: String, contenders: usize) {
- let barrier = std::sync::Arc::new(std::sync::Barrier::new(contenders));
- let handles: Vec<_> = (0..contenders)
- .map(|i| {
- let (barrier, url) = (std::sync::Arc::clone(&barrier), url.clone());
- std::thread::spawn(move || {
- let runtime = tokio::runtime::Builder::new_current_thread()
- .enable_all()
- .build()
- .unwrap();
- runtime.block_on(async move {
- let backend = crate::storage::open(&url).await.unwrap();
- let leases =
- DocumentLeases::cluster(backend.as_ref(), format!("n{i}"), None, TTL)
- .unwrap();
- leases.holder("race").await.unwrap();
- barrier.wait();
- leases.acquire("race", 0).await
- })
- })
- })
- .collect();
- let outcomes: Vec<_> = handles.into_iter().map(|h| h.join().unwrap()).collect();
- let winners: Vec<_> = outcomes.iter().filter_map(|o| o.as_ref().ok()).collect();
- assert_eq!(winners.len(), 1, "{outcomes:?}");
- assert_eq!(winners[0].epoch, 1);
- for outcome in &outcomes {
- match outcome {
- Ok(_) => {}
- Err(LeaseError::Held(record)) => assert_eq!(record.epoch, 1),
- Err(other) => panic!("unexpected {other:?}"),
- }
- }
-}
-
-#[cfg(feature = "storage-sqlite")]
-#[test]
-fn sqlite_threads_racing_for_a_key_have_one_winner() {
- for round in 0..5 {
- let dir = tempfile::tempdir().unwrap();
- let url = format!(
- "sqlite:{}",
- dir.path().join(format!("leases-{round}.db")).display()
- );
- race_on(url, 8);
- }
-}
-
#[tokio::test]
async fn renew_after_expiry_is_lost_even_without_takeover() {
let storage = MemoryStorage::new();
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 11814b9263..475eff5673 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -321,12 +321,23 @@ pub fn driver_is_shared(driver: &str) -> bool {
driver == "mongodb"
}
-/// Whether a backend with this driver name makes a compare-and-swap
+/// Whether an opened backend makes a compare-and-swap
/// (`Precondition::Version` / `Absent`) atomic across processes, which a
-/// [`lease::DocumentLeases`] needs to exclude other nodes. MongoDB and SQLite
-/// do (a database-side conditional write; SQLite's immediate transaction
-/// under the file lock); the memory driver lives in one process, and the
-/// file driver checks versions in-process only.
+/// [`lease::DocumentLeases`] needs to exclude other nodes. The driver says so
+/// itself with [`Capability::SharedAcrossProcesses`], and
+/// tinystoragedrivers' `conformance::run_shared` proves the claim per driver.
+pub fn backend_has_cross_process_cas(backend: &dyn StorageBackend) -> bool {
+ backend
+ .capabilities()
+ .contains(Capability::SharedAcrossProcesses)
+}
+
+/// The same answer from a driver name alone, for the boot guard, which judges
+/// a configured URL before anything is opened (so it has no backend to ask).
+/// It must agree with [`backend_has_cross_process_cas`]: MongoDB and SQLite
+/// claim `SharedAcrossProcesses`; the memory driver lives in one process and
+/// the file driver checks versions in-process only. A test opens a real
+/// backend per driver and pins the two together.
pub fn driver_has_cross_process_cas(driver: &str) -> bool {
matches!(driver, "mongodb" | "sqlite")
}