Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion src/webxdc/webxdc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::chatlist::Chatlist;
use crate::config::Config;
use crate::ephemeral;
use crate::securejoin::get_securejoin_qr;
use crate::test_utils;
use crate::test_utils::{self, TimeShiftFalsePositiveNote};
use crate::test_utils::{E2EE_INFO_MSGS, TestContext, TestContextManager};
use crate::tools::{self, SystemTime};
use crate::{message, sql};
Expand Down Expand Up @@ -1827,6 +1827,59 @@ async fn test_status_update_vs_delete_device_after() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_status_update_vs_ephemeral_timer() -> Result<()> {
let _n = TimeShiftFalsePositiveNote;
let alice = &TestContext::new_alice().await;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests better use TestContextManager, even if there is only one context, but definitely if there are multiple contexts:

let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;

This currently has not much advantage since with_log_sink() is removed, but if it is restored or more features are implemented in the context manager, then test will use it.

let bob = &TestContext::new_bob().await;

// Alice creates a chat with Bob and sets ephemeral messages to 60 minutes
let alice_chat = alice.create_chat(bob).await;
alice_chat
.id
.set_ephemeral_timer(
alice,
ephemeral::Timer::Enabled {
duration: 3600.try_into()?,
},
)
.await?;
bob.recv_msg(&alice.pop_sent_msg().await).await;

// Alice sends an app
let alice_instance = send_webxdc_instance(alice, alice_chat.id).await?;
let bob_instance = bob.recv_msg(&alice.pop_sent_msg().await).await;
bob_instance.chat_id.accept(bob).await?;
message::markseen_msgs(bob, vec![bob_instance.id]).await?;

// 30 minutes later, Alice sends a status update
SystemTime::shift(Duration::from_secs(1800));
alice
.send_webxdc_status_update(alice_instance.id, r#"{"payload":1}"#)
.await?;
alice.flush_status_updates().await?;
bob.recv_msg_trash(&alice.pop_sent_msg().await).await;
bob.send_webxdc_status_update(bob_instance.id, r#"{"payload":2}"#)
.await?;

// further 45 minutes later, both apps are deleted, although the last status update is only 45 minutes old:
// status updates do not extend the ephemeral timer
SystemTime::shift(Duration::from_secs(2700));
ephemeral::delete_expired_messages(bob, tools::time()).await?;
ephemeral::delete_expired_messages(alice, tools::time()).await?;
assert!(
Message::load_from_db_optional(bob, bob_instance.id)
.await?
.is_none()
);
assert!(
Message::load_from_db_optional(alice, alice_instance.id)
.await?
.is_none()
);
Ok(())
}

async fn has_incoming_webxdc_event(
t: &TestContext,
expected_msg: Message,
Expand Down
Loading