Add test for housekeeping cleanup of old call SDPs

Co-authored-by: link2xt <18373967+link2xt@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-06 20:11:06 +00:00
parent c556b07380
commit 19be18dcbf
2 changed files with 99 additions and 14 deletions

View File

@@ -672,3 +672,76 @@ async fn test_no_partial_calls() -> Result<()> {
Ok(()) Ok(())
} }
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_housekeeping_deletes_old_call_sdps() -> Result<()> {
use crate::sql::housekeeping;
let alice = TestContext::new_alice().await;
let bob = alice.create_chat_with_contact("", "bob@example.net").await;
// Place a call
let call_id = alice
.place_outgoing_call(bob.id, PLACE_INFO.to_string())
.await?;
// Verify SDP is stored in calls table
let sdp_before: Option<String> = alice
.sql
.query_row_optional(
"SELECT offer_sdp FROM calls WHERE msg_id=?",
(call_id,),
|row| row.get(0),
)
.await?;
assert_eq!(sdp_before, Some(PLACE_INFO.to_string()));
// End the call
alice.end_call(call_id).await?;
// Verify the call message is marked as ended
let call = alice.load_call_by_id(call_id).await?.unwrap();
assert!(call.is_ended());
// SDP should still be there after ending
let sdp_after_end: Option<String> = alice
.sql
.query_row_optional(
"SELECT offer_sdp FROM calls WHERE msg_id=?",
(call_id,),
|row| row.get(0),
)
.await?;
assert_eq!(sdp_after_end, Some(PLACE_INFO.to_string()));
// Simulate passage of time by modifying the message timestamp
// to be older than 24 hours
let old_timestamp = crate::tools::time() - 86400 - 1; // 24 hours + 1 second ago
alice
.sql
.execute(
"UPDATE msgs SET timestamp_sent=? WHERE id=?",
(old_timestamp, call_id),
)
.await?;
// Run housekeeping
housekeeping(&alice).await?;
// Verify SDP has been deleted from calls table
let sdp_after_housekeeping: Option<String> = alice
.sql
.query_row_optional(
"SELECT offer_sdp FROM calls WHERE msg_id=?",
(call_id,),
|row| row.get(0),
)
.await?;
assert_eq!(sdp_after_housekeeping, None);
// The call message should still exist
let msg = Message::load_from_db(&alice, call_id).await?;
assert_eq!(msg.viewtype, Viewtype::Call);
Ok(())
}

View File

@@ -1682,7 +1682,18 @@ impl MimeFactory {
)); ));
// Get SDP answer from the referenced call message in calls table, // Get SDP answer from the referenced call message in calls table,
// or fall back to params if not yet migrated // or fall back to params if not yet migrated
if let Some(ref quoted_msg_id) = msg.in_reply_to { if let Some(ref quoted_rfc724_mid) = msg.in_reply_to {
// Look up msg_id from rfc724_mid first
let quoted_msg_id: Option<MsgId> = context
.sql
.query_row_optional(
"SELECT id FROM msgs WHERE rfc724_mid=?",
(quoted_rfc724_mid,),
|row| row.get(0),
)
.await?;
if let Some(quoted_msg_id) = quoted_msg_id {
let answer_sdp = context let answer_sdp = context
.sql .sql
.query_row_optional( .query_row_optional(
@@ -1702,6 +1713,7 @@ impl MimeFactory {
} }
} }
} }
}
SystemMessage::CallEnded => { SystemMessage::CallEnded => {
headers.push(( headers.push((
"Chat-Content", "Chat-Content",