Skip to content

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

chore(tests): add import_once test module

Steven Enamakel17424bcd0ccf
diff --git a/crates/openhuman-core/src/modules/import_once_tests.rs b/crates/openhuman-core/src/modules/import_once_tests.rs
index 86909ef9a1..7dbaa15c8f 100644
--- a/crates/openhuman-core/src/modules/import_once_tests.rs
+++ b/crates/openhuman-core/src/modules/import_once_tests.rs
@@ -11,10 +11,11 @@ impl Settled for Done {
#[tokio::test]
async fn a_concurrent_caller_waits_for_the_running_import() {
+ let ctx = crate::core::runtime::DispatchCtx::host_default();
let dir = std::path::PathBuf::from("/import-once/concurrent");
let finished = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
let flag = finished.clone();
- let first = import_once(&crate::core::runtime::DispatchCtx::host_default(), "test-concurrent", MODULE_FOR_TEST, &dir, async move {
+ let first = import_once(&ctx, "test-concurrent", MODULE_FOR_TEST, &dir, async move {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
flag.store(true, std::sync::atomic::Ordering::SeqCst);
Ok(Done(true))
@@ -22,7 +23,7 @@ async fn a_concurrent_caller_waits_for_the_running_import() {
let flag = finished.clone();
let second = async {
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
- import_once(&crate::core::runtime::DispatchCtx::host_default(), "test-concurrent", MODULE_FOR_TEST, &dir, async {
+ import_once(&ctx, "test-concurrent", MODULE_FOR_TEST, &dir, async {
panic!("a settled import must not run a second time");
#[allow(unreachable_code)]
Ok(Done(true))
@@ -39,29 +40,30 @@ async fn a_concurrent_caller_waits_for_the_running_import() {
#[tokio::test]
async fn an_unsettled_outcome_and_a_cancelled_import_are_retried() {
+ let ctx = crate::core::runtime::DispatchCtx::host_default();
let dir = std::path::PathBuf::from("/import-once/retry");
let runs = std::sync::atomic::AtomicUsize::new(0);
let count = || runs.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
- import_once(&crate::core::runtime::DispatchCtx::host_default(), "test-retry", MODULE_FOR_TEST, &dir, async {
+ import_once(&ctx, "test-retry", MODULE_FOR_TEST, &dir, async {
count();
Ok(Done(false))
})
.await;
let cancelled = tokio::time::timeout(
std::time::Duration::from_millis(500),
- import_once(&crate::core::runtime::DispatchCtx::host_default(), "test-retry", MODULE_FOR_TEST, &dir, async {
+ import_once(&ctx, "test-retry", MODULE_FOR_TEST, &dir, async {
count();
std::future::pending::<anyhow::Result<Done>>().await
}),
)
.await;
assert!(cancelled.is_err());
- import_once(&crate::core::runtime::DispatchCtx::host_default(), "test-retry", MODULE_FOR_TEST, &dir, async {
+ import_once(&ctx, "test-retry", MODULE_FOR_TEST, &dir, async {
count();
Ok(Done(true))
})
.await;
- import_once(&crate::core::runtime::DispatchCtx::host_default(), "test-retry", MODULE_FOR_TEST, &dir, async {
+ import_once(&ctx, "test-retry", MODULE_FOR_TEST, &dir, async {
count();
Ok(Done(true))
})