From d839777ca37d1cc6dad42273308c71a5c5e424b6 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sat, 4 Apr 2026 19:57:48 -0300 Subject: [PATCH] test: Message sent from future shall not stick to the bottom (#8027) Currently this fails, so if the user fixes their clock incorrectly set to the future, they need to delete previously sent messages or wait until this future comes again. --- src/chat/chat_tests.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 76cbc131c..70e06fdd2 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -5034,6 +5034,33 @@ async fn test_do_not_overwrite_draft() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_outgoing_msg_after_another_from_future() -> Result<()> { + let mut tcm = TestContextManager::new(); + let t = &tcm.alice().await; + let chat_id = t.get_self_chat().await.id; + // Simulate sending a message with clock set to the future. + let msg_id = send_text_msg(t, chat_id, "test".to_string()).await?; + t.sql + .execute( + "UPDATE msgs SET timestamp=timestamp+3600 WHERE id=?", + (msg_id,), + ) + .await?; + let timestamp_sent: i64 = t + .sql + .query_get_value("SELECT timestamp_sent FROM msgs WHERE id=?", (msg_id,)) + .await? + .unwrap(); + // Let's have a check here that locally sent messages have zero `timestamp_sent`, it can be a + // useful invariant. + assert_eq!(timestamp_sent, 0); + + let msg_id = send_text_msg(t, chat_id, "Fixed my clock".to_string()).await?; + assert_eq!(t.get_last_msg_in(chat_id).await.id, msg_id); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_info_contact_id() -> Result<()> { let mut tcm = TestContextManager::new();