Skip to content

Commit 81ca8c2

Browse files
committed
remove partial download tests and fix issues in other tests
1 parent a40c82c commit 81ca8c2

File tree

10 files changed

+73
-624
lines changed

10 files changed

+73
-624
lines changed

deltachat-rpc-client/tests/test_something.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -620,60 +620,6 @@ def test_mdn_doesnt_break_autocrypt(acfactory) -> None:
620620
assert snapshot.show_padlock
621621

622622

623-
def test_reaction_to_partially_fetched_msg(acfactory, tmp_path):
624-
"""See https://github.com/deltachat/deltachat-core-rust/issues/3688 "Partially downloaded
625-
messages are received out of order".
626-
627-
If the Inbox contains X small messages followed by Y large messages followed by Z small
628-
messages, Delta Chat first downloaded a batch of X+Z messages, and then a batch of Y messages.
629-
630-
This bug was discovered by @Simon-Laux while testing reactions PR #3644 and can be reproduced
631-
with online test as follows:
632-
- Bob enables download limit and goes offline.
633-
- Alice sends a large message to Bob and reacts to this message with a thumbs-up.
634-
- Bob goes online
635-
- Bob first processes a reaction message and throws it away because there is no corresponding
636-
message, then processes a partially downloaded message.
637-
- As a result, Bob does not see a reaction
638-
"""
639-
download_limit = 300000
640-
ac1, ac2 = acfactory.get_online_accounts(2)
641-
ac1_addr = ac1.get_config("addr")
642-
chat = ac1.create_chat(ac2)
643-
ac2.set_config("download_limit", str(download_limit))
644-
ac2.stop_io()
645-
646-
logging.info("sending small+large messages from ac1 to ac2")
647-
msgs = []
648-
msgs.append(chat.send_text("hi"))
649-
path = tmp_path / "large"
650-
path.write_bytes(os.urandom(download_limit + 1))
651-
msgs.append(chat.send_file(str(path)))
652-
for m in msgs:
653-
m.wait_until_delivered()
654-
655-
logging.info("sending a reaction to the large message from ac1 to ac2")
656-
# TODO: Find the reason of an occasional message reordering on the server (so that the reaction
657-
# has a lower UID than the previous message). W/a is to sleep for some time to let the reaction
658-
# have a later INTERNALDATE.
659-
time.sleep(1.1)
660-
react_str = "\N{THUMBS UP SIGN}"
661-
msgs.append(msgs[-1].send_reaction(react_str))
662-
msgs[-1].wait_until_delivered()
663-
664-
ac2.start_io()
665-
666-
logging.info("wait for ac2 to receive a reaction")
667-
msg2 = Message(ac2, ac2.wait_for_reactions_changed().msg_id)
668-
assert msg2.get_sender_contact().get_snapshot().address == ac1_addr
669-
assert msg2.get_snapshot().download_state == DownloadState.AVAILABLE
670-
reactions = msg2.get_reactions()
671-
contacts = [Contact(ac2, int(i)) for i in reactions.reactions_by_contact]
672-
assert len(contacts) == 1
673-
assert contacts[0].get_snapshot().address == ac1_addr
674-
assert list(reactions.reactions_by_contact.values())[0] == [react_str]
675-
676-
677623
def test_reactions_for_a_reordering_move(acfactory, direct_imap):
678624
"""When a batch of messages is moved from Inbox to DeltaChat folder with a single MOVE command,
679625
their UIDs may be reordered (e.g. Gmail is known for that) which led to that messages were

src/calls/calls_tests.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -652,20 +652,13 @@ async fn test_no_partial_calls() -> Result<()> {
652652
Chat-Content: call-ended\n\
653653
\n\
654654
Call ended\n";
655-
receive_imf_from_inbox(
656-
alice,
657-
658-
imf_raw,
659-
seen,
660-
Some(imf_raw.len().try_into().unwrap()),
661-
)
662-
.await?;
655+
receive_imf_from_inbox(alice, "[email protected]", imf_raw, seen).await?;
663656

664657
// The call is still not ended.
665658
assert_eq!(call_state(alice, call_msg.id).await?, CallState::Alerting);
666659

667660
// Fully downloading the message ends the call.
668-
receive_imf_from_inbox(alice, "[email protected]", imf_raw, seen, None)
661+
receive_imf_from_inbox(alice, "[email protected]", imf_raw, seen)
669662
.await
670663
.context("Failed to fully download end call message")?;
671664
assert_eq!(call_state(alice, call_msg.id).await?, CallState::Missed);

src/chat/chat_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,7 @@ async fn test_broadcast_channel_protected_listid() -> Result<()> {
29372937
.await?
29382938
.grpid;
29392939

2940-
let parsed = mimeparser::MimeMessage::from_bytes(bob, sent.payload.as_bytes(), None).await?;
2940+
let parsed = mimeparser::MimeMessage::from_bytes(bob, sent.payload.as_bytes()).await?;
29412941
assert_eq!(
29422942
parsed.get_mailinglist_header().unwrap(),
29432943
format!("My Channel <{}>", alice_list_id)
@@ -3035,7 +3035,7 @@ async fn test_leave_broadcast_multidevice() -> Result<()> {
30353035
remove_contact_from_chat(bob0, bob_chat_id, ContactId::SELF).await?;
30363036

30373037
let leave_msg = bob0.pop_sent_msg().await;
3038-
let parsed = MimeMessage::from_bytes(bob1, leave_msg.payload().as_bytes(), None).await?;
3038+
let parsed = MimeMessage::from_bytes(bob1, leave_msg.payload().as_bytes()).await?;
30393039
assert_eq!(
30403040
parsed.parts[0].msg,
30413041
stock_str::msg_group_left_remote(bob0).await

src/download.rs

Lines changed: 2 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,8 @@ mod tests {
218218
use num_traits::FromPrimitive;
219219

220220
use super::*;
221-
use crate::chat::{get_chat_msgs, send_msg};
222-
use crate::ephemeral::Timer;
223-
use crate::message::delete_msgs;
224-
use crate::receive_imf::receive_imf_from_inbox;
225-
use crate::test_utils::{E2EE_INFO_MSGS, TestContext, TestContextManager};
221+
use crate::chat::send_msg;
222+
use crate::test_utils::TestContext;
226223

227224
#[test]
228225
fn test_downloadstate_values() {
@@ -294,230 +291,4 @@ mod tests {
294291

295292
Ok(())
296293
}
297-
298-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
299-
async fn test_partial_receive_imf() -> Result<()> {
300-
let t = TestContext::new_alice().await;
301-
302-
let header = "Received: (Postfix, from userid 1000); Mon, 4 Dec 2006 14:51:39 +0100 (CET)\n\
303-
304-
305-
Subject: foo\n\
306-
Message-ID: <[email protected]>\n\
307-
Chat-Version: 1.0\n\
308-
Date: Sun, 22 Mar 2020 22:37:57 +0000\
309-
Content-Type: text/plain";
310-
311-
receive_imf_from_inbox(
312-
&t,
313-
314-
header.as_bytes(),
315-
false,
316-
Some(100000),
317-
)
318-
.await?;
319-
let msg = t.get_last_msg().await;
320-
assert_eq!(msg.download_state(), DownloadState::Available);
321-
assert_eq!(msg.get_subject(), "foo");
322-
assert!(
323-
msg.get_text()
324-
.contains(&stock_str::partial_download_msg_body(&t, 100000).await)
325-
);
326-
327-
receive_imf_from_inbox(
328-
&t,
329-
330-
format!("{header}\n\n100k text...").as_bytes(),
331-
false,
332-
None,
333-
)
334-
.await?;
335-
let msg = t.get_last_msg().await;
336-
assert_eq!(msg.download_state(), DownloadState::Done);
337-
assert_eq!(msg.get_subject(), "foo");
338-
assert_eq!(msg.get_text(), "100k text...");
339-
340-
Ok(())
341-
}
342-
343-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
344-
async fn test_partial_download_and_ephemeral() -> Result<()> {
345-
let t = TestContext::new_alice().await;
346-
let chat_id = t
347-
.create_chat_with_contact("bob", "[email protected]")
348-
.await
349-
.id;
350-
chat_id
351-
.set_ephemeral_timer(&t, Timer::Enabled { duration: 60 })
352-
.await?;
353-
354-
// download message from bob partially, this must not change the ephemeral timer
355-
receive_imf_from_inbox(
356-
&t,
357-
358-
b"From: Bob <[email protected]>\n\
359-
To: Alice <[email protected]>\n\
360-
Chat-Version: 1.0\n\
361-
Subject: subject\n\
362-
Message-ID: <[email protected]>\n\
363-
Date: Sun, 14 Nov 2021 00:10:00 +0000\
364-
Content-Type: text/plain",
365-
false,
366-
Some(100000),
367-
)
368-
.await?;
369-
assert_eq!(
370-
chat_id.get_ephemeral_timer(&t).await?,
371-
Timer::Enabled { duration: 60 }
372-
);
373-
374-
Ok(())
375-
}
376-
377-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
378-
async fn test_status_update_expands_to_nothing() -> Result<()> {
379-
let alice = TestContext::new_alice().await;
380-
let bob = TestContext::new_bob().await;
381-
let chat_id = alice.create_chat(&bob).await.id;
382-
383-
let file = alice.get_blobdir().join("minimal.xdc");
384-
tokio::fs::write(&file, include_bytes!("../test-data/webxdc/minimal.xdc")).await?;
385-
let mut instance = Message::new(Viewtype::File);
386-
instance.set_file_and_deduplicate(&alice, &file, None, None)?;
387-
let _sent1 = alice.send_msg(chat_id, &mut instance).await;
388-
389-
alice
390-
.send_webxdc_status_update(instance.id, r#"{"payload":7}"#)
391-
.await?;
392-
alice.flush_status_updates().await?;
393-
let sent2 = alice.pop_sent_msg().await;
394-
let sent2_rfc724_mid = sent2.load_from_db().await.rfc724_mid;
395-
396-
// not downloading the status update results in an placeholder
397-
receive_imf_from_inbox(
398-
&bob,
399-
&sent2_rfc724_mid,
400-
sent2.payload().as_bytes(),
401-
false,
402-
Some(sent2.payload().len() as u32),
403-
)
404-
.await?;
405-
let msg = bob.get_last_msg().await;
406-
let chat_id = msg.chat_id;
407-
assert_eq!(
408-
get_chat_msgs(&bob, chat_id).await?.len(),
409-
E2EE_INFO_MSGS + 1
410-
);
411-
assert_eq!(msg.download_state(), DownloadState::Available);
412-
413-
// downloading the status update afterwards expands to nothing and moves the placeholder to trash-chat
414-
// (usually status updates are too small for not being downloaded directly)
415-
receive_imf_from_inbox(
416-
&bob,
417-
&sent2_rfc724_mid,
418-
sent2.payload().as_bytes(),
419-
false,
420-
None,
421-
)
422-
.await?;
423-
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), E2EE_INFO_MSGS);
424-
assert!(
425-
Message::load_from_db_optional(&bob, msg.id)
426-
.await?
427-
.is_none()
428-
);
429-
430-
Ok(())
431-
}
432-
433-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
434-
async fn test_mdn_expands_to_nothing() -> Result<()> {
435-
let bob = TestContext::new_bob().await;
436-
let raw = b"Subject: Message opened\n\
437-
Date: Mon, 10 Jan 2020 00:00:00 +0000\n\
438-
Chat-Version: 1.0\n\
439-
Message-ID: <[email protected]>\n\
440-
To: Alice <[email protected]>\n\
441-
From: Bob <[email protected]>\n\
442-
Content-Type: multipart/report; report-type=disposition-notification;\n\t\
443-
boundary=\"kJBbU58X1xeWNHgBtTbMk80M5qnV4N\"\n\
444-
\n\
445-
\n\
446-
--kJBbU58X1xeWNHgBtTbMk80M5qnV4N\n\
447-
Content-Type: text/plain; charset=utf-8\n\
448-
\n\
449-
bla\n\
450-
\n\
451-
\n\
452-
--kJBbU58X1xeWNHgBtTbMk80M5qnV4N\n\
453-
Content-Type: message/disposition-notification\n\
454-
\n\
455-
Reporting-UA: Delta Chat 1.88.0\n\
456-
Original-Recipient: rfc822;[email protected]\n\
457-
Final-Recipient: rfc822;[email protected]\n\
458-
Original-Message-ID: <[email protected]>\n\
459-
Disposition: manual-action/MDN-sent-automatically; displayed\n\
460-
\n\
461-
\n\
462-
--kJBbU58X1xeWNHgBtTbMk80M5qnV4N--\n\
463-
";
464-
465-
// not downloading the mdn results in an placeholder
466-
receive_imf_from_inbox(&bob, "[email protected]", raw, false, Some(raw.len() as u32)).await?;
467-
let msg = bob.get_last_msg().await;
468-
let chat_id = msg.chat_id;
469-
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), 1);
470-
assert_eq!(msg.download_state(), DownloadState::Available);
471-
472-
// downloading the mdn afterwards expands to nothing and deletes the placeholder directly
473-
// (usually mdn are too small for not being downloaded directly)
474-
receive_imf_from_inbox(&bob, "[email protected]", raw, false, None).await?;
475-
assert_eq!(get_chat_msgs(&bob, chat_id).await?.len(), 0);
476-
assert!(
477-
Message::load_from_db_optional(&bob, msg.id)
478-
.await?
479-
.is_none()
480-
);
481-
482-
Ok(())
483-
}
484-
485-
/// Tests that fully downloading the message
486-
/// works even if the Message-ID already exists
487-
/// in the database assigned to the trash chat.
488-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
489-
async fn test_partial_download_trashed() -> Result<()> {
490-
let mut tcm = TestContextManager::new();
491-
let alice = &tcm.alice().await;
492-
493-
let imf_raw = b"From: Bob <[email protected]>\n\
494-
To: Alice <[email protected]>\n\
495-
Chat-Version: 1.0\n\
496-
Subject: subject\n\
497-
Message-ID: <[email protected]>\n\
498-
Date: Sun, 14 Nov 2021 00:10:00 +0000\
499-
Content-Type: text/plain";
500-
501-
// Download message from Bob partially.
502-
let partial_received_msg =
503-
receive_imf_from_inbox(alice, "[email protected]", imf_raw, false, Some(100000))
504-
.await?
505-
.unwrap();
506-
assert_eq!(partial_received_msg.msg_ids.len(), 1);
507-
508-
// Delete the received message.
509-
// Not it is still in the database,
510-
// but in the trash chat.
511-
delete_msgs(alice, &[partial_received_msg.msg_ids[0]]).await?;
512-
513-
// Fully download message after deletion.
514-
let full_received_msg =
515-
receive_imf_from_inbox(alice, "[email protected]", imf_raw, false, None).await?;
516-
517-
// The message does not reappear.
518-
// However, `receive_imf` should not fail.
519-
assert!(full_received_msg.is_none());
520-
521-
Ok(())
522-
}
523294
}

src/mimefactory/mimefactory_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ async fn test_render_reply() {
558558
"1.0"
559559
);
560560

561-
let _mime_msg = MimeMessage::from_bytes(context, rendered_msg.message.as_bytes(), None)
561+
let _mime_msg = MimeMessage::from_bytes(context, rendered_msg.message.as_bytes())
562562
.await
563563
.unwrap();
564564
}
@@ -824,7 +824,7 @@ async fn test_protected_headers_directive() -> Result<()> {
824824
assert!(msg.get_showpadlock());
825825
assert!(sent.payload.contains("\r\nSubject: [...]\r\n"));
826826

827-
let mime = MimeMessage::from_bytes(&alice, sent.payload.as_bytes(), None).await?;
827+
let mime = MimeMessage::from_bytes(&alice, sent.payload.as_bytes()).await?;
828828
let mut payload = str::from_utf8(&mime.decoded_data)?.splitn(2, "\r\n\r\n");
829829
let part = payload.next().unwrap();
830830
assert_eq!(
@@ -854,7 +854,7 @@ async fn test_dont_remove_self() -> Result<()> {
854854
.await;
855855

856856
println!("{}", sent.payload);
857-
let mime_message = MimeMessage::from_bytes(alice, sent.payload.as_bytes(), None)
857+
let mime_message = MimeMessage::from_bytes(alice, sent.payload.as_bytes())
858858
.await
859859
.unwrap();
860860
assert!(!mime_message.header_exists(HeaderDef::ChatGroupPastMembers));

0 commit comments

Comments
 (0)