Skip to content

Commit 4fdd476

Browse files
committed
test: MDN on pre-message has effect if received before sending full message (#8004)
This currently fails: after sending the full message, the message state is `OutDelivered` like if there was no MDN.
1 parent e0803bf commit 4fdd476

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ pub enum Config {
427427
/// storing the same token multiple times on the server.
428428
EncryptedDeviceToken,
429429

430+
/// Make `TestContext::pop_sent_msg_opt()` and related functions pop messages from the `smtp`
431+
/// head, i.e. make it a queue. For historical reasons the default is a stack.
432+
PopSentMsgFromHead,
433+
430434
/// Enables running test hooks, e.g. see `InnerContext::pre_encrypt_mime_hook`.
431435
/// This way is better than conditional compilation, i.e. `#[cfg(test)]`, because tests not
432436
/// using this still run unmodified code.

src/test_utils.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,16 +624,25 @@ impl TestContext {
624624
}
625625

626626
pub async fn pop_sent_msg_opt(&self, timeout: Duration) -> Option<SentMessage<'_>> {
627+
let from_head = self
628+
.get_config_bool(Config::PopSentMsgFromHead)
629+
.await
630+
.unwrap();
631+
let order_subst = match from_head {
632+
true => "",
633+
false => " DESC",
634+
};
627635
let start = Instant::now();
628636
let (rowid, msg_id, payload, recipients) = loop {
629637
let row = self
630638
.ctx
631639
.sql
632640
.query_row_optional(
633-
r#"
634-
SELECT id, msg_id, mime, recipients
635-
FROM smtp
636-
ORDER BY id DESC"#,
641+
&format!(
642+
"SELECT id, msg_id, mime, recipients
643+
FROM smtp
644+
ORDER BY id{order_subst}"
645+
),
637646
(),
638647
|row| {
639648
let rowid: i64 = row.get(0)?;

src/tests/pre_messages/receiving.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use pretty_assertions::assert_eq;
44

55
use crate::EventType;
66
use crate::chat;
7+
use crate::config::Config;
78
use crate::contact;
89
use crate::download::{DownloadState, PRE_MSG_ATTACHMENT_SIZE_THRESHOLD, PostMsgMetadata};
910
use crate::message::{Message, MessageState, Viewtype, delete_msgs, markseen_msgs};
@@ -253,6 +254,49 @@ async fn test_lost_pre_msg() -> Result<()> {
253254
Ok(())
254255
}
255256

257+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
258+
async fn test_pre_msg_mdn() -> Result<()> {
259+
let mut tcm = TestContextManager::new();
260+
let alice = &tcm.alice().await;
261+
alice
262+
.set_config_bool(Config::PopSentMsgFromHead, true)
263+
.await?;
264+
let bob = &tcm.bob().await;
265+
let alice_chat_id = alice.create_group_with_members("", &[bob]).await;
266+
267+
let file_bytes = include_bytes!("../../../test-data/image/screenshot.gif");
268+
let mut msg = Message::new(Viewtype::Image);
269+
msg.set_file_from_bytes(alice, "a.jpg", file_bytes, None)?;
270+
msg.set_text("populate".to_string());
271+
let pre_msg = alice.send_msg(alice_chat_id, &mut msg).await;
272+
let alice_msg_id = msg.id;
273+
274+
let msg = bob.recv_msg(&pre_msg).await;
275+
assert_eq!(msg.download_state, DownloadState::Available);
276+
assert_eq!(msg.id.get_state(bob).await?, MessageState::InFresh);
277+
assert_eq!(msg.text, "populate");
278+
markseen_msgs(bob, vec![msg.id]).await?;
279+
assert_eq!(msg.id.get_state(bob).await?, MessageState::InSeen);
280+
assert_eq!(
281+
bob.sql.count("SELECT COUNT(*) FROM smtp_mdns", ()).await?,
282+
1
283+
);
284+
smtp::queue_mdn(bob).await?;
285+
alice.recv_msg_trash(&bob.pop_sent_msg().await).await;
286+
assert_eq!(
287+
alice_msg_id.get_state(alice).await?,
288+
MessageState::OutPending
289+
);
290+
291+
let _full_msg = alice.pop_sent_msg().await;
292+
// BUG: Must be `OutMdnRcvd`
293+
assert_eq!(
294+
alice_msg_id.get_state(alice).await?,
295+
MessageState::OutDelivered
296+
);
297+
Ok(())
298+
}
299+
256300
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
257301
async fn test_post_msg_bad_sender() -> Result<()> {
258302
let mut tcm = TestContextManager::new();

0 commit comments

Comments
 (0)