Skip to content

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

test(storage): add round trip test for storage bridge

Steven Enamakeldadbe7c129c0
diff --git a/crates/openhuman-core/src/storage/mod_tests.rs b/crates/openhuman-core/src/storage/mod_tests.rs
index 27b323007e..1944e2b31e 100644
--- a/crates/openhuman-core/src/storage/mod_tests.rs
+++ b/crates/openhuman-core/src/storage/mod_tests.rs
@@ -1,5 +1,29 @@
use super::*;
+fn round_trip_through_storage_bridge() -> serde_json::Value {
+ let backend: Arc<dyn StorageBackend> =
+ Arc::new(tinystoragedrivers_testkit::MemoryBackend::new());
+ let storage = backend.for_scope(&Scope::new("bridge-test").unwrap()).unwrap();
+ let docs = Arc::clone(storage.documents());
+ block_on(async move {
+ docs.ensure_collection(&CollectionSpec::new("bridge.records"))
+ .await?;
+ docs.put(
+ "bridge.records",
+ "record-1",
+ serde_json::json!({"value": 42}),
+ Precondition::Absent,
+ )
+ .await?;
+ Ok(docs
+ .get("bridge.records", "record-1")
+ .await?
+ .expect("record was written")
+ .doc)
+ })
+ .unwrap()
+}
+
fn config_with(url: Option<&str>) -> Config {
let mut config = Config::default();
config.storage.url = url.map(str::to_string);
@@ -133,14 +157,12 @@ fn block_on_runs_a_future_from_sync_code() {
#[tokio::test(flavor = "current_thread")]
async fn block_on_works_inside_a_current_thread_runtime() {
- let answer = block_on(async { Ok::<_, StorageError>(7) }).unwrap();
- assert_eq!(answer, 7);
+ assert_eq!(round_trip_through_storage_bridge(), serde_json::json!({"value": 42}));
}
#[tokio::test(flavor = "multi_thread")]
async fn block_on_works_inside_a_multi_thread_runtime() {
- let answer = block_on(async { Ok::<_, StorageError>(8) }).unwrap();
- assert_eq!(answer, 8);
+ assert_eq!(round_trip_through_storage_bridge(), serde_json::json!({"value": 42}));
}
#[test]