Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/dialog/tests/test_uas_ack_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,18 @@ async fn test_unacked_reinvite_2xx_ends_the_session() -> crate::Result<()> {
Ok(())
}

async fn wait_confirmed(states: &mut DialogStateReceiver) {
/// Wait for `Confirmed` and return the CSeq number of the 2xx it carries.
async fn wait_confirmed(states: &mut DialogStateReceiver) -> u32 {
loop {
let state = tokio::time::timeout(Duration::from_secs(2), states.recv())
.await
.expect("timeout waiting for the call to be confirmed")
.expect("state channel closed");
if matches!(state, DialogState::Confirmed(..)) {
return;
if let DialogState::Confirmed(_, resp) = state {
let cseq = resp.cseq_header().expect("Confirmed carries the 2xx");
assert_eq!(cseq.method().unwrap(), Method::Invite);
assert_eq!(resp.status_code.code(), 200);
return cseq.seq().unwrap();
}
}
}
Expand Down Expand Up @@ -652,7 +656,7 @@ async fn test_2xx_over_tcp_is_retransmitted_until_the_ack() -> crate::Result<()>
.write_all(request(Method::Ack, 1, Some(&to_tag)).as_bytes())
.await?;
let acked = Instant::now();
wait_confirmed(&mut states).await;
assert_eq!(wait_confirmed(&mut states).await, 1);
let after_ack = read_tcp_messages(&mut stream, &mut buf, acked + T1 * 30).await;
assert!(
!after_ack
Expand Down Expand Up @@ -790,7 +794,7 @@ async fn test_late_ack_of_an_earlier_reinvite_reaches_its_own_transaction() -> c
};
let local_tag = ok.to_header()?.tag()?.unwrap().value().to_string();
peer.send_request(Method::Ack, 1, Some(&local_tag)).await;
wait_confirmed(&mut states).await;
assert_eq!(wait_confirmed(&mut states).await, 1);

// re-INVITE 2 and 3 are answered; the ACK of 2 arrives after re-INVITE 3.
let mut answered = None;
Expand Down Expand Up @@ -854,6 +858,9 @@ async fn test_late_ack_of_an_earlier_reinvite_reaches_its_own_transaction() -> c
)),
"an ACKed call must not be ended"
);
// Each ACK confirms its own re-INVITE, in the order the ACKs arrived.
assert_eq!(wait_confirmed(&mut states).await, 2);
assert_eq!(wait_confirmed(&mut states).await, 3);
assert!(terminated_reason(&mut states).is_none());
assert!(dialog.state().is_confirmed());
token.cancel();
Expand Down
8 changes: 7 additions & 1 deletion src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,9 +1612,15 @@ impl Transaction {
}
self.last_ack.take().map(SipMessage::Request)
}
TransactionType::ServerNonInvite | TransactionType::ServerInvite => {
TransactionType::ServerNonInvite => {
self.last_response.take().map(SipMessage::Response)
}
// Kept: the matching ACK terminates an Accepted server
// INVITE before the dialog reads the 2xx for
// `DialogState::Confirmed`.
TransactionType::ServerInvite => {
self.last_response.clone().map(SipMessage::Response)
}
_ => None,
}
};
Expand Down
Loading