diff --git a/crates/irtt-client/src/managed/task.rs b/crates/irtt-client/src/managed/task.rs index 28841ab..2ad601b 100644 --- a/crates/irtt-client/src/managed/task.rs +++ b/crates/irtt-client/src/managed/task.rs @@ -188,12 +188,15 @@ impl ManagedClientHandle { /// Subscribe to authoritative durable latest-state observation. /// + /// The current snapshot is marked as seen when subscribing. /// The current snapshot is immediately available through `borrow()`. Updates /// may coalesce; this is not a lossless event log. After the task terminates, /// the sender closes but the final snapshot remains readable. Use /// [`Self::subscribe`] for the lossy presentation-event stream. pub fn subscribe_status(&self) -> ManagedStatusSubscription { - self.status.clone() + let mut status = self.status.clone(); + drop(status.borrow_and_update()); + status } /// Subscribe to future lossy presentation events. diff --git a/crates/irtt-client/tests/managed_control.rs b/crates/irtt-client/tests/managed_control.rs index 908ea3b..37f2511 100644 --- a/crates/irtt-client/tests/managed_control.rs +++ b/crates/irtt-client/tests/managed_control.rs @@ -27,6 +27,25 @@ fn stop_resolves_every_accepted_update_and_closes_admission() { ); assert!(!subscription.borrow().stop_requested); assert!(subscription.borrow().final_outcome.is_none()); + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + let mut task = pin!(task); + { + let _runtime = runtime.enter(); + assert!(task + .as_mut() + .poll(&mut Context::from_waker(Waker::noop())) + .is_pending()); + } + assert_eq!(handle.status().lifecycle, ManagedLifecycle::Running); + subscription = handle.subscribe_status(); + assert_eq!(subscription.borrow().lifecycle, ManagedLifecycle::Running); + assert!(pin!(subscription.changed()) + .as_mut() + .poll(&mut Context::from_waker(Waker::noop())) + .is_pending()); let receipts: Vec<_> = (0..3) .map(|index| { handle @@ -52,10 +71,6 @@ fn stop_resolves_every_accepted_update_and_closes_admission() { handle.update_targets(vec![]), Err(ManagedCommandError::Stopping) )); - let runtime = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); runtime.block_on(async { tokio::time::timeout(Duration::from_secs(2), async { let outcome = task.await;