Skip to content

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

test(channels): cache linked module fixture client

Steven Enamakelb030148862b3
diff --git a/crates/openhuman-core/src/channels/module_fixture_tests.rs b/crates/openhuman-core/src/channels/module_fixture_tests.rs
index ab19065624..62a0701bd6 100644
--- a/crates/openhuman-core/src/channels/module_fixture_tests.rs
+++ b/crates/openhuman-core/src/channels/module_fixture_tests.rs
@@ -16,27 +16,43 @@ use std::sync::Arc;
use tinybus::module::ModuleClient;
#[cfg(feature = "e2e-test-support")]
use tinychannels_bus::methods;
+use tokio::sync::OnceCell;
const MODULE_ID: &str = "tinychannels";
+static CLIENT: OnceCell<ModuleClient> = OnceCell::const_new();
/// Return a client for the compiled, linked TinyChannels module fixture.
pub(crate) async fn client() -> ModuleClient {
- register_linked(MODULE_ID, tinychannels_module::linked_module);
- let mut config = Config::default();
- config.modules.allow_download = false;
- config.modules.source = ModuleSourceMode::Linked;
- ops::ensure_loaded(&config, MODULE_ID)
+ CLIENT
+ .get_or_init(|| async {
+ register_linked(MODULE_ID, tinychannels_module::linked_module);
+ let mut config = Config::default();
+ config.modules.allow_download = false;
+ config.modules.source = ModuleSourceMode::Linked;
+ ops::ensure_loaded(&config, MODULE_ID)
+ .await
+ .expect("the linked TinyChannels module should be admitted through the seam");
+ let proxy = runtime::runtime()
+ .await
+ .expect("the module host should be running")
+ .proxy(
+ tinychannels_module::BUS_NAME,
+ tinychannels_module::OBJECT_PATH,
+ )
+ .expect("the linked TinyChannels proxy should be valid");
+ ops::fixture_client(proxy)
+ })
.await
- .expect("the linked TinyChannels module should be admitted through the seam");
- let proxy = runtime::runtime()
- .await
- .expect("the module host should be running")
- .proxy(
- tinychannels_module::BUS_NAME,
- tinychannels_module::OBJECT_PATH,
- )
- .expect("the linked TinyChannels proxy should be valid");
- ops::fixture_client(proxy)
+ .clone()
+}
+
+#[tokio::test]
+async fn concurrent_linked_module_client_requests_share_the_ready_fixture() {
+ let (first, second, third) = tokio::join!(client(), client(), client());
+
+ assert!(first.fixture_proxy().is_some());
+ assert!(second.fixture_proxy().is_some());
+ assert!(third.fixture_proxy().is_some());
}
/// Temporarily install in-memory storage for module callbacks in isolated tests.