BlueGit

ict rusty-teams

fix(calls): Cancel and timeout work while an outgoing call is set up

- waiting for the one-call-at-a-time gate can be cancelled
- creating the conversation, joining and the first endpoint update listen for Cancel and give up after 30 s
- fixes the setup step test that 6babff6 picked up half done (did not compile)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-09 · 3 weeks ago

Hash
e111d47dcdec9ba04b48ea6dcf1b3a023eb4aaff
Parent
6babff60
1 file changed +16 −4
crates/calling/src/call.rs +16 −4
@@ -711,7 +711,18 @@ async fn setup_step<T, E>(control: &mut CallControl, step: impl std::future::Fut
711 711 where
712 712 Error: From<E>,
713 713 {
714 match control.until_hangup(timeout(SETUP_STEP_TIMEOUT, step)).await? {
714 setup_step_within(control, SETUP_STEP_TIMEOUT, step).await
715 }
716
717 async fn setup_step_within<T, E>(
718 control: &mut CallControl,
719 limit: Duration,
720 step: impl std::future::Future<Output = std::result::Result<T, E>>,
721 ) -> Result<T>
722 where
723 Error: From<E>,
724 {
725 match control.until_hangup(timeout(limit, step)).await? {
715 726 Ok(result) => Ok(result?),
716 727 Err(_) => Err(Error::Signaling("Teams did not answer in time".into())),
717 728 }
@@ -3579,13 +3590,14 @@ async fn collect_stats(peer: &PeerConnection, share_mids: &[String]) -> StatsSna
3579 3590
3580 3591 #[cfg(test)]
3581 3592 mod tests {
3582 #[tokio::test(start_paused = true)]
3593 #[tokio::test]
3583 3594 async fn a_hanging_setup_step_ends_on_cancel_or_after_the_step_timeout() {
3584 3595 let (handle, mut control) = crate::control::call_channel();
3585 3596 handle.commands.send(CallCommand::Hangup).unwrap();
3586 let cancelled = setup_step(&mut control, std::future::pending::<std::result::Result<(), Error>>()).await;
3597 let limit = Duration::from_millis(20);
3598 let cancelled = setup_step_within(&mut control, limit, std::future::pending::<std::result::Result<(), Error>>()).await;
3587 3599 assert!(matches!(cancelled, Err(Error::Cancelled)));
3588 let timed_out = setup_step(&mut control, std::future::pending::<std::result::Result<(), Error>>()).await;
3600 let timed_out = setup_step_within(&mut control, limit, std::future::pending::<std::result::Result<(), Error>>()).await;
3589 3601 assert!(matches!(timed_out, Err(Error::Signaling(_))));
3590 3602 }
3591 3603
@@ -711,7 +711,18 @@ async fn setup_step<T, E>(control: &mut CallControl, step: impl std::future::Fut
711where
711where
712 Error: From<E>,
712 Error: From<E>,
713{
713{
714 match control.until_hangup(timeout(SETUP_STEP_TIMEOUT, step)).await? {
714 setup_step_within(control, SETUP_STEP_TIMEOUT, step).await
715}
716
717async fn setup_step_within<T, E>(
718 control: &mut CallControl,
719 limit: Duration,
720 step: impl std::future::Future<Output = std::result::Result<T, E>>,
721) -> Result<T>
722where
723 Error: From<E>,
724{
725 match control.until_hangup(timeout(limit, step)).await? {
715 Ok(result) => Ok(result?),
726 Ok(result) => Ok(result?),
716 Err(_) => Err(Error::Signaling("Teams did not answer in time".into())),
727 Err(_) => Err(Error::Signaling("Teams did not answer in time".into())),
717 }
728 }
@@ -3579,13 +3590,14 @@ async fn collect_stats(peer: &PeerConnection, share_mids: &[String]) -> StatsSna
3579
3590
3580#[cfg(test)]
3591#[cfg(test)]
3581mod tests {
3592mod tests {
3582 #[tokio::test(start_paused = true)]
3593 #[tokio::test]
3583 async fn a_hanging_setup_step_ends_on_cancel_or_after_the_step_timeout() {
3594 async fn a_hanging_setup_step_ends_on_cancel_or_after_the_step_timeout() {
3584 let (handle, mut control) = crate::control::call_channel();
3595 let (handle, mut control) = crate::control::call_channel();
3585 handle.commands.send(CallCommand::Hangup).unwrap();
3596 handle.commands.send(CallCommand::Hangup).unwrap();
3586 let cancelled = setup_step(&mut control, std::future::pending::<std::result::Result<(), Error>>()).await;
3597 let limit = Duration::from_millis(20);
3598 let cancelled = setup_step_within(&mut control, limit, std::future::pending::<std::result::Result<(), Error>>()).await;
3587 assert!(matches!(cancelled, Err(Error::Cancelled)));
3599 assert!(matches!(cancelled, Err(Error::Cancelled)));
3588 let timed_out = setup_step(&mut control, std::future::pending::<std::result::Result<(), Error>>()).await;
3600 let timed_out = setup_step_within(&mut control, limit, std::future::pending::<std::result::Result<(), Error>>()).await;
3589 assert!(matches!(timed_out, Err(Error::Signaling(_))));
3601 assert!(matches!(timed_out, Err(Error::Signaling(_))));
3590 }
3602 }
3591
3603