Skip to content

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

test(orchestration): share test turn registry and assert busy state via is_busy

Steven Enamakelf31178cc0f0c
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
index 7044b3197e..403b79c0bc 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
@@ -56,7 +56,7 @@ use slot::DeliverySlot;
use super::background_completions;
use super::busy_guard::is_busy;
#[cfg(test)]
-use super::busy_guard::{busy, clear_busy_for_thread, TurnBusy};
+use super::busy_guard::{clear_busy_for_thread, TurnBusy};
use super::completion_notice::build_undelivered_notice;
use super::completion_owners;
use super::delivery_drain::{DrainFence, RECOVERY_BUSY_POLL};
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
index f4101dc0e8..9fe8fadcdb 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs
@@ -229,14 +229,15 @@ async fn desktop_keys_are_the_bare_ids() {
let turn = in_scope(&desktop, || {
TurnBusy::start(&DispatchCtx::ambient(), &session)
});
- assert_eq!(turn.key, session);
- assert!(busy().lock().unwrap().contains_key(&session));
assert!(in_scope(&desktop, || is_busy(
&DispatchCtx::ambient(),
&thread
)));
drop(turn);
- assert!(!busy().lock().unwrap().contains_key(&session));
+ assert!(!in_scope(&desktop, || is_busy(
+ &DispatchCtx::ambient(),
+ &thread
+ )));
let router = router_for_workspace(ws.path());
let slot = in_scope(&desktop, || {
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
index 38bb817da6..ea56c75dce 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs
@@ -31,20 +31,21 @@ fn pending_ids(ws: &Path, thread: &str) -> Vec<String> {
.collect()
}
-fn mark_busy(session: &str) {
+fn test_turns() -> &'static std::sync::Mutex<std::collections::HashMap<String, TurnBusy>> {
static TURNS: std::sync::OnceLock<std::sync::Mutex<std::collections::HashMap<String, TurnBusy>>> =
std::sync::OnceLock::new();
- TURNS
- .get_or_init(Default::default)
+ TURNS.get_or_init(Default::default)
+}
+
+fn mark_busy(session: &str) {
+ test_turns()
.lock()
.expect("test turns")
.insert(session.to_owned(), TurnBusy::start(&cx(), session));
}
fn clear_busy(session: &str) {
- static TURNS: std::sync::OnceLock<std::sync::Mutex<std::collections::HashMap<String, TurnBusy>>> =
- std::sync::OnceLock::new();
- TURNS.get_or_init(Default::default).lock().expect("test turns").remove(session);
+ test_turns().lock().expect("test turns").remove(session);
}
#[tokio::test]