|
1 | 1 | //! Tests about receiving Pre-Messages and Post-Message |
2 | | -use anyhow::Result; |
| 2 | +use anyhow::{Context as _, Result}; |
3 | 3 | use pretty_assertions::assert_eq; |
4 | 4 |
|
5 | 5 | use crate::EventType; |
@@ -175,6 +175,44 @@ async fn test_receive_pre_message_and_dl_post_message() -> Result<()> { |
175 | 175 | Ok(()) |
176 | 176 | } |
177 | 177 |
|
| 178 | +/// Test receiving the Post-Message after receiving the pre-message twice. |
| 179 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 180 | +async fn test_receive_pre_message_twice() -> Result<()> { |
| 181 | + let mut tcm = TestContextManager::new(); |
| 182 | + let alice = &tcm.alice().await; |
| 183 | + let bob = &tcm.bob().await; |
| 184 | + let alice_group_id = alice.create_group_with_members("test group", &[bob]).await; |
| 185 | + |
| 186 | + let (pre_message, post_message, _alice_msg_id) = |
| 187 | + send_large_file_message(alice, alice_group_id, Viewtype::File, &vec![0u8; 1_000_000]) |
| 188 | + .await?; |
| 189 | + |
| 190 | + let msg = bob.recv_msg(&pre_message).await; |
| 191 | + assert!(bob.recv_msg_opt(&pre_message).await.is_none()); |
| 192 | + |
| 193 | + // Pre-message should still be there. |
| 194 | + // Due to a bug receiving pre-message second time |
| 195 | + // deleted it in 2.44.0. |
| 196 | + // This is a regression test. |
| 197 | + let msg = Message::load_from_db(bob, msg.id) |
| 198 | + .await |
| 199 | + .context("Pre-message should still exist after receiving it twice")?; |
| 200 | + assert_eq!(msg.download_state(), DownloadState::Available); |
| 201 | + assert_eq!(msg.viewtype, Viewtype::Text); |
| 202 | + assert!(msg.param.exists(Param::PostMessageViewtype)); |
| 203 | + assert!(msg.param.exists(Param::PostMessageFileBytes)); |
| 204 | + assert_eq!(msg.text, "test".to_owned()); |
| 205 | + |
| 206 | + let _ = bob.recv_msg_trash(&post_message).await; |
| 207 | + let msg = Message::load_from_db(bob, msg.id).await?; |
| 208 | + assert_eq!(msg.download_state(), DownloadState::Done); |
| 209 | + assert_eq!(msg.viewtype, Viewtype::File); |
| 210 | + assert_eq!(msg.param.exists(Param::PostMessageViewtype), false); |
| 211 | + assert_eq!(msg.param.exists(Param::PostMessageFileBytes), false); |
| 212 | + assert_eq!(msg.text, "test".to_owned()); |
| 213 | + Ok(()) |
| 214 | +} |
| 215 | + |
178 | 216 | /// Test out of order receiving. Post-Message is received & downloaded before pre-message. |
179 | 217 | /// In that case pre-message shall be trashed. |
180 | 218 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
|
0 commit comments