Skip to content

Commit f961a49

Browse files
committed
test: remove timeout from pop_sent_msg_ex()
Arbitrary timeouts often result in flaky tests, especially if CI runners may be paused. In this case however timeout was not used by any tests and only slowed down the tests in cases where no message is expected but non-zero timeout is set.
1 parent b98b323 commit f961a49

8 files changed

Lines changed: 38 additions & 74 deletions

File tree

src/chat/chat_tests.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,15 +1281,15 @@ async fn test_marknoticed_all_chats() -> Result<()> {
12811281

12821282
tcm.section("bob: receive messages, accept all chats and send a reply to each messsage");
12831283

1284-
while let Some(sent_msg) = alice.pop_sent_msg_opt(Duration::default()).await {
1284+
while let Some(sent_msg) = alice.pop_sent_msg_opt().await {
12851285
let bob_message = bob.recv_msg(&sent_msg).await;
12861286
let bob_chat_id = bob_message.chat_id;
12871287
bob_chat_id.accept(bob).await?;
12881288
send_text_msg(bob, bob_chat_id, "reply".to_string()).await?;
12891289
}
12901290

12911291
tcm.section("alice: receive replies from bob");
1292-
while let Some(sent_msg) = bob.pop_sent_msg_opt(Duration::default()).await {
1292+
while let Some(sent_msg) = bob.pop_sent_msg_opt().await {
12931293
alice.recv_msg(&sent_msg).await;
12941294
}
12951295
// ensure chats have unread messages
@@ -2816,7 +2816,7 @@ async fn test_cant_remove_nonmember() -> Result<()> {
28162816

28172817
let alice_charlie_id = alice.add_or_lookup_contact_id(charlie).await;
28182818
remove_contact_from_chat(alice, alice_broadcast_id, alice_charlie_id).await?;
2819-
assert!(alice.pop_sent_msg_opt(Duration::ZERO).await.is_none());
2819+
assert!(alice.pop_sent_msg_opt().await.is_none());
28202820
assert!(!remove_from_chat_contacts_table(alice, alice_broadcast_id, alice_charlie_id).await?);
28212821
assert!(
28222822
!remove_from_chat_contacts_table_without_trace(alice, alice_broadcast_id, alice_charlie_id)
@@ -3067,10 +3067,7 @@ async fn test_broadcast_resend_to_new_member() -> Result<()> {
30673067
}
30683068
for i in 0..N_MSGS_TO_NEW_BROADCAST_MEMBER {
30693069
let rev_order = false;
3070-
let resent_msg = alice
3071-
.pop_sent_msg_ex(rev_order, Duration::ZERO)
3072-
.await
3073-
.unwrap();
3070+
let resent_msg = alice.pop_sent_msg_ex(rev_order).await.unwrap();
30743071
let fiona_msg = fiona.recv_msg(&resent_msg).await;
30753072
assert_eq!(fiona_msg.chat_id, fiona_bc_id);
30763073
assert_eq!(fiona_msg.text, (i + 1).to_string());
@@ -3087,7 +3084,7 @@ async fn test_broadcast_resend_to_new_member() -> Result<()> {
30873084
);
30883085
bob.recv_msg_trash(&resent_msg).await;
30893086
}
3090-
assert!(alice.pop_sent_msg_opt(Duration::ZERO).await.is_none());
3087+
assert!(alice.pop_sent_msg_opt().await.is_none());
30913088
Ok(())
30923089
}
30933090

@@ -3552,12 +3549,7 @@ async fn test_chat_description(
35523549

35533550
tcm.section("Alice calls set_chat_description() without actually changing the description");
35543551
set_chat_description(alice, alice_chat_id, "ä ẟ 😂").await?;
3555-
assert!(
3556-
alice
3557-
.pop_sent_msg_opt(Duration::from_secs(0))
3558-
.await
3559-
.is_none()
3560-
);
3552+
assert!(alice.pop_sent_msg_opt().await.is_none());
35613553

35623554
Ok(())
35633555
}
@@ -3582,12 +3574,7 @@ async fn test_setting_empty_chat_description() -> Result<()> {
35823574
let _hi = alice.send_text(alice_chat_id, "hi").await;
35833575

35843576
set_chat_description(alice, alice_chat_id, "").await?;
3585-
assert!(
3586-
alice
3587-
.pop_sent_msg_opt(Duration::from_secs(0))
3588-
.await
3589-
.is_none()
3590-
);
3577+
assert!(alice.pop_sent_msg_opt().await.is_none());
35913578

35923579
Ok(())
35933580
}

src/ephemeral/ephemeral_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async fn test_ephemeral_unpromoted() -> Result<()> {
171171
chat_id
172172
.set_ephemeral_timer(&alice, Timer::Enabled { duration: 60 })
173173
.await?;
174-
let sent = alice.pop_sent_msg_opt(Duration::from_secs(1)).await;
174+
let sent = alice.pop_sent_msg_opt().await;
175175
assert!(sent.is_none());
176176
assert_eq!(
177177
chat_id.get_ephemeral_timer(&alice).await?,
@@ -181,13 +181,13 @@ async fn test_ephemeral_unpromoted() -> Result<()> {
181181
// Promote the group.
182182
send_text_msg(&alice, chat_id, "hi!".to_string()).await?;
183183
assert!(chat_id.is_promoted(&alice).await?);
184-
let sent = alice.pop_sent_msg_opt(Duration::from_secs(1)).await;
184+
let sent = alice.pop_sent_msg_opt().await;
185185
assert!(sent.is_some());
186186

187187
chat_id
188188
.set_ephemeral_timer(&alice.ctx, Timer::Disabled)
189189
.await?;
190-
let sent = alice.pop_sent_msg_opt(Duration::from_secs(1)).await;
190+
let sent = alice.pop_sent_msg_opt().await;
191191
assert!(sent.is_some());
192192
assert_eq!(chat_id.get_ephemeral_timer(&alice).await?, Timer::Disabled);
193193

src/mimeparser/mimeparser_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use mailparse::ParsedMail;
22
use std::mem;
3-
use std::time::Duration;
43

54
use super::*;
65
use crate::{
@@ -1435,7 +1434,7 @@ async fn test_intended_recipient_fingerprint() -> Result<()> {
14351434
let chat_id = chat::create_group(t, "").await?;
14361435

14371436
chat::send_text_msg(t, chat_id, "hi!".to_string()).await?;
1438-
assert!(t.pop_sent_msg_opt(Duration::ZERO).await.is_none());
1437+
assert!(t.pop_sent_msg_opt().await.is_none());
14391438

14401439
for (i, member) in members.iter().enumerate() {
14411440
let contact = t.add_or_lookup_contact(member).await;

src/receive_imf/receive_imf_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,12 +2030,12 @@ async fn test_no_smtp_job_for_self_chat() -> Result<()> {
20302030
let chat_id = bob.get_self_chat().await.id;
20312031
let mut msg = Message::new_text("Happy birthday to me".to_string());
20322032
chat::send_msg(bob, chat_id, &mut msg).await?;
2033-
assert!(bob.pop_sent_msg_opt(Duration::ZERO).await.is_none());
2033+
assert!(bob.pop_sent_msg_opt().await.is_none());
20342034

20352035
bob.set_config_bool(Config::BccSelf, true).await?;
20362036
let mut msg = Message::new_text("Happy birthday to me".to_string());
20372037
chat::send_msg(bob, chat_id, &mut msg).await?;
2038-
assert!(bob.pop_sent_msg_opt(Duration::ZERO).await.is_some());
2038+
assert!(bob.pop_sent_msg_opt().await.is_some());
20392039

20402040
Ok(())
20412041
}

src/securejoin/securejoin_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ async fn test_parallel_setup_contact(bob_deletes_fiona_contact: bool) -> Result<
950950
Contact::delete(bob, bob_fiona_contact_id).await?;
951951

952952
bob.recv_msg_trash(&sent_fiona_vc_auth_required).await;
953-
let sent = bob.pop_sent_msg_opt(Duration::ZERO).await;
953+
let sent = bob.pop_sent_msg_opt().await;
954954
assert!(sent.is_none());
955955
} else {
956956
bob.recv_msg_trash(&sent_fiona_vc_auth_required).await;
@@ -1235,7 +1235,7 @@ async fn test_rejoin_group() -> Result<()> {
12351235
assert_eq!(progress, 1000);
12361236

12371237
// Bob does not send any more messages by scanning the QR code.
1238-
assert!(bob.pop_sent_msg_opt(Duration::ZERO).await.is_none());
1238+
assert!(bob.pop_sent_msg_opt().await.is_none());
12391239

12401240
Ok(())
12411241
}

src/test_utils.rs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::{Deref, DerefMut};
88
use std::panic;
99
use std::path::Path;
1010
use std::sync::{Arc, LazyLock};
11-
use std::time::{Duration, Instant};
11+
use std::time::Duration;
1212

1313
use anyhow::Result;
1414
use async_channel::{self as channel, Receiver, Sender};
@@ -283,10 +283,10 @@ impl TestContextManager {
283283
inviters: &[&TestContext],
284284
qr: &str,
285285
) -> ChatId {
286-
assert!(joiner.pop_sent_msg_opt(Duration::ZERO).await.is_none());
286+
assert!(joiner.pop_sent_msg_opt().await.is_none());
287287
let inviter_addr = inviters[0].get_primary_self_addr().await.unwrap();
288288
for inviter in inviters {
289-
assert!(inviter.pop_sent_msg_opt(Duration::ZERO).await.is_none());
289+
assert!(inviter.pop_sent_msg_opt().await.is_none());
290290
assert_eq!(inviter.get_primary_self_addr().await.unwrap(), inviter_addr);
291291
}
292292

@@ -295,14 +295,14 @@ impl TestContextManager {
295295
for _ in 0..2 {
296296
let mut something_sent = false;
297297
let rev_order = false;
298-
if let Some(sent) = joiner.pop_sent_msg_ex(rev_order, Duration::ZERO).await {
298+
if let Some(sent) = joiner.pop_sent_msg_ex(rev_order).await {
299299
for inviter in inviters {
300300
inviter.recv_msg_opt(&sent).await;
301301
}
302302
something_sent = true;
303303
}
304304
for inviter in inviters {
305-
if let Some(sent) = inviter.pop_sent_msg_ex(rev_order, Duration::ZERO).await {
305+
if let Some(sent) = inviter.pop_sent_msg_ex(rev_order).await {
306306
if sent.recipients.split(' ').any(|addr| addr == inviter_addr) {
307307
for observer in inviters {
308308
// `imap::prefetch_should_download()` returns false on the sender side.
@@ -649,22 +649,17 @@ impl TestContext {
649649
///
650650
/// Panics if there is no message or on any error.
651651
pub async fn pop_sent_msg(&self) -> SentMessage<'_> {
652-
self.pop_sent_msg_opt(Duration::from_secs(3))
652+
self.pop_sent_msg_opt()
653653
.await
654654
.expect("no sent message found in jobs table")
655655
}
656656

657-
pub async fn pop_sent_msg_opt(&self, timeout: Duration) -> Option<SentMessage<'_>> {
657+
pub async fn pop_sent_msg_opt(&self) -> Option<SentMessage<'_>> {
658658
let rev_order = true;
659-
self.pop_sent_msg_ex(rev_order, timeout).await
659+
self.pop_sent_msg_ex(rev_order).await
660660
}
661661

662-
pub async fn pop_sent_msg_ex(
663-
&self,
664-
rev_order: bool,
665-
timeout: Duration,
666-
) -> Option<SentMessage<'_>> {
667-
let start = Instant::now();
662+
pub async fn pop_sent_msg_ex(&self, rev_order: bool) -> Option<SentMessage<'_>> {
668663
let mut query = "
669664
SELECT id, msg_id, mime, recipients
670665
FROM smtp
@@ -673,28 +668,18 @@ ORDER BY id"
673668
if rev_order {
674669
query += " DESC";
675670
}
676-
let (rowid, msg_id, payload, recipients) = loop {
677-
let row = self
678-
.ctx
679-
.sql
680-
.query_row_optional(&query, (), |row| {
681-
let rowid: i64 = row.get(0)?;
682-
let msg_id: MsgId = row.get(1)?;
683-
let mime: String = row.get(2)?;
684-
let recipients: String = row.get(3)?;
685-
Ok((rowid, msg_id, mime, recipients))
686-
})
687-
.await
688-
.expect("query_row_optional failed");
689-
if let Some(row) = row {
690-
break row;
691-
}
692-
if start.elapsed() < timeout {
693-
tokio::time::sleep(Duration::from_millis(100)).await;
694-
} else {
695-
return None;
696-
}
697-
};
671+
let (rowid, msg_id, payload, recipients) = self
672+
.ctx
673+
.sql
674+
.query_row_optional(&query, (), |row| {
675+
let rowid: i64 = row.get(0)?;
676+
let msg_id: MsgId = row.get(1)?;
677+
let mime: String = row.get(2)?;
678+
let recipients: String = row.get(3)?;
679+
Ok((rowid, msg_id, mime, recipients))
680+
})
681+
.await
682+
.expect("query_row_optional failed")?;
698683
self.ctx
699684
.sql
700685
.execute("DELETE FROM smtp WHERE id=?;", (rowid,))

src/tests/pre_messages/forward_and_save.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Tests about forwarding and saving Pre-Messages
2-
use std::time::Duration;
32
43
use anyhow::Result;
54
use pretty_assertions::assert_eq;
@@ -108,12 +107,7 @@ async fn test_receive_both() -> Result<()> {
108107
forward_msgs(alice, &[alice_msg_id], alice_chat_id).await?;
109108
let rev_order = false;
110109
let msg = bob
111-
.recv_msg(
112-
&alice
113-
.pop_sent_msg_ex(rev_order, Duration::ZERO)
114-
.await
115-
.unwrap(),
116-
)
110+
.recv_msg(&alice.pop_sent_msg_ex(rev_order).await.unwrap())
117111
.await;
118112
assert_eq!(msg.download_state(), DownloadState::Available);
119113
assert_eq!(msg.is_forwarded(), true);

src/webxdc/integration.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ mod tests {
145145
use crate::message::{Message, Viewtype};
146146
use crate::test_utils::TestContext;
147147
use anyhow::Result;
148-
use std::time::Duration;
149148

150149
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
151150
async fn test_default_integrations_are_single_device() -> Result<()> {
@@ -158,7 +157,7 @@ mod tests {
158157
t.set_webxdc_integration(file.to_str().unwrap()).await?;
159158

160159
// default integrations are shipped with the apps and should not be sent over the wire
161-
let sent = t.pop_sent_msg_opt(Duration::from_secs(1)).await;
160+
let sent = t.pop_sent_msg_opt().await;
162161
assert!(sent.is_none());
163162

164163
Ok(())

0 commit comments

Comments
 (0)