Skip to content

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

test(channels): cover channel service startup gated on sign-in

Steven Enamakelffc603aff655
diff --git a/crates/openhuman-core/src/channels/runtime/session_tests.rs b/crates/openhuman-core/src/channels/runtime/session_tests.rs
index bf475c8815..4d47547a15 100644
--- a/crates/openhuman-core/src/channels/runtime/session_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/session_tests.rs
@@ -114,6 +114,7 @@ async fn channel_sign_in_resumes_listener_service_after_logout() {
session.cancelled().await;
let completed_cleanup = cleanups.fetch_add(1, Ordering::SeqCst) + 1;
let _ = cleaned_tx.send((generation, completed_cleanup));
+ Ok(())
}
});
@@ -123,19 +124,20 @@ async fn channel_sign_in_resumes_listener_service_after_logout() {
controller.resume();
controller.resume(); // Duplicate sign-in notifications must not fork a listener.
- let (current, cleanups_before_restart) = tokio::time::timeout(
- std::time::Duration::from_secs(1),
- started_rx.recv(),
- )
- .await
- .expect("sign-in wakes the stopped channel service")
- .expect("restarted channel generation");
+ let (current, cleanups_before_restart) =
+ tokio::time::timeout(std::time::Duration::from_secs(1), started_rx.recv())
+ .await
+ .expect("sign-in wakes the stopped channel service")
+ .expect("restarted channel generation");
assert!(old.is_cancelled(), "logout must fence the old generation");
assert!(
!current.is_cancelled(),
"sign-in resumes a fresh generation"
);
- assert_eq!(cleanups_before_restart, 1, "old runtime cleanup must finish before restart");
+ assert_eq!(
+ cleanups_before_restart, 1,
+ "old runtime cleanup must finish before restart"
+ );
assert_eq!(starts.load(Ordering::SeqCst), 2);
controller.invalidate();
@@ -149,3 +151,39 @@ async fn channel_sign_in_resumes_listener_service_after_logout() {
);
service.abort();
}
+
+#[tokio::test]
+async fn channel_service_created_during_logout_waits_for_sign_in() {
+ let controller = ChannelSessionController::new();
+ controller.invalidate();
+ let starts = Arc::new(AtomicUsize::new(0));
+ let observed_starts = Arc::clone(&starts);
+ let (started_tx, mut started_rx) = tokio::sync::mpsc::unbounded_channel();
+ let service = spawn_channel_service_with(controller.clone(), move |session| {
+ let starts = Arc::clone(&observed_starts);
+ let started_tx = started_tx.clone();
+ async move {
+ starts.fetch_add(1, Ordering::SeqCst);
+ let _ = started_tx.send(session.clone());
+ session.cancelled().await;
+ Ok(())
+ }
+ });
+
+ assert!(
+ tokio::time::timeout(std::time::Duration::from_millis(20), started_rx.recv())
+ .await
+ .is_err()
+ );
+ assert_eq!(starts.load(Ordering::SeqCst), 0);
+
+ controller.resume();
+ let resumed = tokio::time::timeout(std::time::Duration::from_secs(1), started_rx.recv())
+ .await
+ .expect("credential installation resumes startup")
+ .expect("resumed channel generation");
+ assert!(!resumed.is_cancelled());
+ assert_eq!(starts.load(Ordering::SeqCst), 1);
+ controller.invalidate();
+ service.abort();
+}
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
index d32a0c0164..a9ef945be4 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -172,9 +172,8 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->
// Do not drop preparation after it may have acquired a module
// lease. Finish it and await the runtime's acknowledged close
// before the service supervisor can admit another identity.
- if let Ok(mut runtime) = preparing.await {
- runtime.close().await?;
- }
+ let mut runtime = preparing.await?;
+ runtime.close().await?;
return Ok(());
},
prepared = &mut preparing => {