Skip to content

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

test(cron): pass ambient dispatch context in scheduler tests

Steven Enamakel3fc017c868d7
diff --git a/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
index 01941a9146..13b7f986a9 100644
--- a/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_classifier_and_delivery_tests.rs
@@ -488,7 +488,7 @@ async fn scheduler_tick_once_publishes_health_recovery_signal_on_empty_queue() {
tick_once(
&config,
&mut last_emitted_health,
- &mut JobDispatcher::new(&config, &security),
+ &mut JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security),
)
.await;
@@ -551,7 +551,7 @@ async fn scheduler_tick_once_does_not_re_emit_recovery_signal_on_steady_state()
tick_once(
&config,
&mut last_emitted_health,
- &mut JobDispatcher::new(&config, &security),
+ &mut JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security),
)
.await;
assert_eq!(
@@ -569,7 +569,7 @@ async fn scheduler_tick_once_does_not_re_emit_recovery_signal_on_steady_state()
tick_once(
&config,
&mut last_emitted_health,
- &mut JobDispatcher::new(&config, &security),
+ &mut JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security),
)
.await;
assert_eq!(
diff --git a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
index a8fd94947a..05cd7a2397 100644
--- a/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_dispatch_tests.rs
@@ -115,7 +115,7 @@ async fn a_long_job_does_not_hold_up_the_next_poll() {
let _fast = register("dispatch-fast", counting(Arc::clone(&fast_calls), Ok(())));
let slow = due_system_job(&config, "dispatch-slow");
- let mut dispatcher = JobDispatcher::new(&config, &security);
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security);
let mut health = None;
// First poll picks up only the slow job.
tick_once(&config, &mut health, &mut dispatcher).await;
@@ -170,7 +170,7 @@ async fn dispatch_claims_the_slot_so_a_running_job_is_not_due_again() {
}),
);
let job = due_system_job(&config, "dispatch-claim");
- let mut dispatcher = JobDispatcher::new(&config, &security(&config));
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security(&config));
dispatcher.dispatch(vec![job.clone()]).await.unwrap();
let stored = cron::get_job(&config, &job.id).unwrap();
assert!(stored.next_run > Utc::now(), "the running slot is claimed");
@@ -190,7 +190,7 @@ async fn a_job_already_in_flight_is_not_dispatched_again() {
let _handler = register("dispatch-dedupe", counting(Arc::clone(&calls), Ok(())));
let job = due_system_job(&config, "dispatch-dedupe");
let running = crate::cron::ops::try_acquire_run(&job.id).expect("the job is free");
- let mut dispatcher = JobDispatcher::new(&config, &security(&config));
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security(&config));
dispatcher.dispatch(vec![job.clone()]).await.unwrap();
dispatcher.drain().await;
drop(running);
@@ -219,7 +219,7 @@ async fn a_single_flight_job_records_the_missed_slot_as_skipped() {
.unwrap();
let job = cron::get_job(&config, &job.id).unwrap();
let running = crate::cron::ops::try_acquire_run(&job.id).expect("the job is free");
- let mut dispatcher = JobDispatcher::new(&config, &security(&config));
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security(&config));
dispatcher.dispatch(vec![job.clone()]).await.unwrap();
dispatcher.drain().await;
drop(running);
@@ -260,7 +260,7 @@ async fn zero_retries_means_exactly_one_attempt() {
)
.unwrap();
let job = cron::get_job(&config, &job.id).unwrap();
- let (success, output) = execute_job_now(&config, &job, "dispatch-run").await;
+ let (success, output) = execute_job_now(&crate::core::runtime::DispatchCtx::ambient(), &config, &job, "dispatch-run").await;
assert!(!success);
assert!(output.contains("boom"), "{output}");
assert_eq!(calls.load(Ordering::SeqCst), 1);
@@ -278,7 +278,7 @@ async fn without_a_policy_the_configured_retry_budget_applies() {
counting(Arc::clone(&calls), Err("again".to_string())),
);
let job = due_system_job(&config, "dispatch-default-retries");
- let (success, _) = execute_job_now(&config, &job, "dispatch-run").await;
+ let (success, _) = execute_job_now(&crate::core::runtime::DispatchCtx::ambient(), &config, &job, "dispatch-run").await;
assert!(!success);
assert_eq!(calls.load(Ordering::SeqCst), 2);
}
@@ -305,7 +305,7 @@ async fn a_system_job_handler_error_is_recorded_as_the_run_result() {
)
.unwrap();
let job = cron::get_job(&config, &job.id).unwrap();
- let mut dispatcher = JobDispatcher::new(&config, &security(&config));
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security(&config));
dispatcher.dispatch(vec![job.clone()]).await.unwrap();
dispatcher.drain().await;
let stored = cron::get_job(&config, &job.id).unwrap();
@@ -321,7 +321,7 @@ async fn a_system_job_without_a_handler_is_still_ok_on_dispatch() {
let tmp = TempDir::new().unwrap();
let config = test_config(&tmp).await;
let job = due_system_job(&config, "dispatch-unclaimed");
- let (success, output) = execute_job_now(&config, &job, "dispatch-run").await;
+ let (success, output) = execute_job_now(&crate::core::runtime::DispatchCtx::ambient(), &config, &job, "dispatch-run").await;
assert!(success);
assert!(output.contains("dispatched"), "{output}");
}
@@ -380,7 +380,7 @@ async fn an_upgraded_job_with_a_side_table_policy_keeps_firing_with_it() {
assert_eq!(job.policy.retries, Some(0));
assert!(job.policy.single_flight);
- let mut dispatcher = JobDispatcher::new(&config, &security(&config));
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security(&config));
dispatcher.dispatch(vec![job]).await.unwrap();
dispatcher.drain().await;
@@ -411,7 +411,7 @@ async fn a_flow_schedule_job_fires_through_the_trigger_sink() {
force_due(&config, &job.id);
let job = cron::get_job(&config, &job.id).unwrap();
- let mut dispatcher = JobDispatcher::new(&config, &security(&config));
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security(&config));
dispatcher.dispatch(vec![job.clone()]).await.unwrap();
dispatcher.drain().await;
@@ -450,7 +450,7 @@ async fn a_flow_schedule_job_is_skipped_when_the_flows_component_is_off() {
let security = security(&config);
let cfg = config.clone();
CoreContext::scope(ctx, async move {
- let mut dispatcher = JobDispatcher::new(&cfg, &security);
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &cfg, &security);
dispatcher.dispatch(vec![job]).await.unwrap();
dispatcher.drain().await;
})
diff --git a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
index 7eb8ff0ea8..608213dd44 100644
--- a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
@@ -367,7 +367,7 @@ async fn run_through_scheduler(config: &Config, job_id: &str) {
&config.workspace_dir,
&config.action_dir,
));
- let mut dispatcher = JobDispatcher::new(config, &security);
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), config, &security);
dispatcher.dispatch(vec![job]).await.unwrap();
dispatcher.drain().await;
}
@@ -427,7 +427,7 @@ async fn scheduler_flow_runs_active_hours_job_and_reschedules_inside_window() {
&config.workspace_dir,
&config.workspace_dir,
));
- let mut dispatcher = JobDispatcher::new(&config, &security);
+ let mut dispatcher = JobDispatcher::new(&crate::core::runtime::DispatchCtx::ambient(), &config, &security);
dispatcher.dispatch(vec![job.clone()]).await.unwrap();
dispatcher.drain().await;
diff --git a/crates/openhuman-core/src/cron/scheduler_tests.rs b/crates/openhuman-core/src/cron/scheduler_tests.rs
index f0821295c7..bf0ce4a92f 100644
--- a/crates/openhuman-core/src/cron/scheduler_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_tests.rs
@@ -172,7 +172,7 @@ async fn retryable_shell_failure_consumes_the_whole_retry_budget() {
let counter = tmp.path().join("retryable-attempts.log");
let job = test_job(&counting_failure_command(&counter));
- let (success, output) = execute_job_now(&config, &job, "test-run").await;
+ let (success, output) = execute_job_now(&crate::core::runtime::DispatchCtx::ambient(), &config, &job, "test-run").await;
assert!(
!success,
@@ -230,7 +230,7 @@ async fn security_policy_block_halts_without_spending_the_retry_budget() {
);
let started = std::time::Instant::now();
- let (success, output) = execute_job_now(&config, &job, "test-run").await;
+ let (success, output) = execute_job_now(&crate::core::runtime::DispatchCtx::ambient(), &config, &job, "test-run").await;
let elapsed = started.elapsed();
assert!(!success, "a blocked job cannot succeed; got {output}");