Skip to content

Commit d323beb

Browse files
committed
add test
1 parent adcc8a9 commit d323beb

File tree

1 file changed

+77
-4
lines changed

1 file changed

+77
-4
lines changed

src/peer_channels.rs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ async fn subscribe_loop(
553553
mod tests {
554554
use super::*;
555555
use crate::{
556-
chat::send_msg,
556+
chat::{self, add_contact_to_chat, resend_msgs, send_msg, ChatId, ProtectionStatus},
557557
message::{Message, Viewtype},
558-
test_utils::TestContextManager,
558+
test_utils::{TestContext, TestContextManager},
559559
EventType,
560560
};
561561

@@ -919,8 +919,30 @@ mod tests {
919919
let alice = &mut tcm.alice().await;
920920
let bob = &mut tcm.bob().await;
921921

922+
let chat = alice.create_chat(&bob).await.id;
923+
924+
let mut instance = Message::new(Viewtype::File);
925+
instance
926+
.set_file_from_bytes(
927+
alice,
928+
"minimal.xdc",
929+
include_bytes!("../test-data/webxdc/minimal.xdc"),
930+
None,
931+
)
932+
.unwrap();
933+
connect_alice_bob(alice, bob, chat, &mut instance).await
934+
}
935+
936+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
937+
async fn test_webxdc_resend() {
938+
let mut tcm = TestContextManager::new();
939+
let alice = &mut tcm.alice().await;
940+
let bob = &mut tcm.bob().await;
941+
let group = chat::create_group_chat(&alice, ProtectionStatus::Unprotected, "")
942+
.await
943+
.unwrap();
944+
922945
// Alice sends webxdc to bob
923-
let alice_chat = alice.create_chat(bob).await;
924946
let mut instance = Message::new(Viewtype::File);
925947
instance
926948
.set_file_from_bytes(
@@ -930,7 +952,58 @@ mod tests {
930952
None,
931953
)
932954
.unwrap();
933-
send_msg(alice, alice_chat.id, &mut instance).await.unwrap();
955+
956+
connect_alice_bob(alice, bob, group, &mut instance).await;
957+
958+
// fiona joins late
959+
let fiona = &mut tcm.fiona().await;
960+
add_contact_to_chat(&alice, group, alice.add_or_lookup_contact_id(&bob).await)
961+
.await
962+
.unwrap();
963+
964+
add_contact_to_chat(&alice, group, alice.add_or_lookup_contact_id(&fiona).await)
965+
.await
966+
.unwrap();
967+
968+
resend_msgs(&alice, &[instance.id]).await.unwrap();
969+
let msg = alice.pop_sent_msg().await;
970+
let fiona_instance = fiona.recv_msg(&msg).await.id;
971+
972+
let fiona_connect_future = send_webxdc_realtime_advertisement(&fiona, fiona_instance)
973+
.await
974+
.unwrap()
975+
.unwrap();
976+
let fiona_advert = fiona.pop_sent_msg().await;
977+
alice.recv_msg_trash(&fiona_advert).await;
978+
979+
fiona_connect_future.await.unwrap();
980+
send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into())
981+
.await
982+
.unwrap();
983+
984+
eprintln!("Waiting for ephemeral message");
985+
loop {
986+
let event = fiona.evtracker.recv().await.unwrap();
987+
if let EventType::WebxdcRealtimeData { data, .. } = event.typ {
988+
if data == b"alice -> bob & fiona" {
989+
break;
990+
} else {
991+
panic!(
992+
"Unexpected status update: {}",
993+
String::from_utf8_lossy(&data)
994+
);
995+
}
996+
}
997+
}
998+
}
999+
1000+
async fn connect_alice_bob(
1001+
alice: &mut TestContext,
1002+
bob: &mut TestContext,
1003+
chat: ChatId,
1004+
instance: &mut Message,
1005+
) {
1006+
send_msg(alice, chat, instance).await.unwrap();
9341007
let alice_webxdc = alice.get_last_msg().await;
9351008

9361009
let webxdc = alice.pop_sent_msg().await;

0 commit comments

Comments
 (0)