Skip to content

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

test(cron): add scheduler dispatch tests

Steven Enamakel1c5637bd5083
diff --git a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
index 05cd7a2397..3566a4aab9 100644
--- a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
@@ -449,8 +449,9 @@ async fn a_flow_schedule_job_is_skipped_when_the_flows_component_is_off() {
let ctx = CoreContext::for_test_with_components(off);
let security = security(&config);
let cfg = config.clone();
+ let dispatch = crate::core::runtime::DispatchCtx::new(Arc::clone(&ctx));
CoreContext::scope(ctx, async move {
- let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &cfg, &security);
+ let mut dispatcher = JobDispatcher::new(&dispatch, &cfg, &security);
dispatcher.dispatch(vec![job]).await.unwrap();
dispatcher.drain().await;
})
@@ -462,3 +463,32 @@ async fn a_flow_schedule_job_is_skipped_when_the_flows_component_is_off() {
assert!(!output.contains("tick emitted"));
assert!(stored.next_run > Utc::now(), "the recurrence moved on");
}
+
+#[tokio::test]
+async fn a_dispatcher_binds_the_context_it_is_handed_not_the_ambient_one() {
+ let (_tmp, config) = test_config().await;
+ let security = security(&config);
+ let handed = CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
+ let ambient = CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
+
+ let dispatcher = CoreContext::scope(Arc::clone(&ambient), async {
+ // Across an await the handed context is still the one bound.
+ tokio::task::yield_now().await;
+ JobDispatcher::new(
+ &crate::core::runtime::DispatchCtx::new(Arc::clone(&handed)),
+ &config,
+ &security,
+ )
+ })
+ .await;
+ let bound = dispatcher.binding.dispatch_ctx();
+ assert!(Arc::ptr_eq(bound.core().expect("bound"), &handed));
+ assert!(!Arc::ptr_eq(bound.core().unwrap(), &ambient));
+
+ // An unbound context binds nothing, whatever the task's scope is.
+ let unbound = CoreContext::scope(ambient, async {
+ JobDispatcher::new(&crate::core::runtime::DispatchCtx::unbound(), &config, &security)
+ })
+ .await;
+ assert!(unbound.binding.context.is_none());
+}