From 2f76fd98dd238d1ff4f0d48e355a46cbde9d70ef Mon Sep 17 00:00:00 2001 From: iequidoo Date: Fri, 3 Apr 2026 14:28:20 -0300 Subject: [PATCH] test: Add test for tweak_sort_timestamp() The part of logic there adjusting the sort timestamp forward if the parent message has a greater sort timestamp wasn't tested explicitly by any test. I only saw one unrelated "golden test" failure when commented it out. (Related to #8027) --- src/receive_imf/receive_imf_tests.rs | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index ecc3c10c0..b0cd0d75a 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -5363,6 +5363,46 @@ async fn test_outgoing_unencrypted_chat_assignment() { assert_eq!(received.chat_id, chat.id); } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_incoming_reply_with_date_in_past() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + + let msg0 = receive_imf( + alice, + b"From: bob@example.net\n\ + To: alice@example.org\n\ + Message-ID: \n\ + Date: Sun, 22 Mar 2020 22:22:22 +0000\n\ + \n\ + This device has an atomic clock\n", + false, + ) + .await? + .unwrap(); + + let msg1 = receive_imf( + alice, + b"From: bob@example.net\n\ + To: alice@example.org\n\ + Message-ID: \n\ + In-Reply-To: \n\ + Date: Sun, 22 Mar 2020 11:11:11 +0000\n\ + \n\ + And this one has a wind-up clock\n", + false, + ) + .await? + .unwrap(); + assert_eq!(msg1.chat_id, msg0.chat_id); + assert!(msg1.sort_timestamp >= msg0.sort_timestamp); + assert_eq!( + alice.get_last_msg_in(msg0.chat_id).await.id, + *msg1.msg_ids.last().unwrap() + ); + Ok(()) +} + /// Tests Bob receiving a message from Alice /// in a new group she just created /// with only Alice and Bob.