Skip to content

Commit 4e47ebd

Browse files
committed
test: fix flaky test_webxdc_resend
1 parent d5c418e commit 4e47ebd

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/peer_channels.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -990,23 +990,41 @@ mod tests {
990990
alice.recv_msg_trash(&fiona_advert).await;
991991

992992
fiona_connect_future.await.unwrap();
993-
send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into())
994-
.await
995-
.unwrap();
996993

997-
loop {
998-
let event = fiona.evtracker.recv().await.unwrap();
999-
if let EventType::WebxdcRealtimeData { data, .. } = event.typ {
1000-
if data == b"alice -> bob & fiona" {
1001-
break;
1002-
} else {
1003-
panic!(
1004-
"Unexpected status update: {}",
1005-
String::from_utf8_lossy(&data)
1006-
);
994+
let realtime_send_loop = async {
995+
// Keep sending in a loop because right after joining
996+
// Fiona may miss messages.
997+
loop {
998+
send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into())
999+
.await
1000+
.unwrap();
1001+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
1002+
}
1003+
};
1004+
1005+
let realtime_receive_loop = async {
1006+
loop {
1007+
let event = fiona.evtracker.recv().await.unwrap();
1008+
if let EventType::WebxdcRealtimeData { data, .. } = event.typ {
1009+
if data == b"alice -> bob & fiona" {
1010+
break;
1011+
} else {
1012+
panic!(
1013+
"Unexpected status update: {}",
1014+
String::from_utf8_lossy(&data)
1015+
);
1016+
}
10071017
}
10081018
}
1009-
}
1019+
};
1020+
tokio::select!(
1021+
_ = realtime_send_loop => {
1022+
panic!("Send loop should never finish");
1023+
},
1024+
_ = realtime_receive_loop => {
1025+
return;
1026+
}
1027+
);
10101028
}
10111029

10121030
async fn connect_alice_bob(

0 commit comments

Comments
 (0)