From 4e47ebd5fcd52bf09282237ea6181a3c0fb84bd8 Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 23 Jul 2025 19:06:20 +0000 Subject: [PATCH] test: fix flaky test_webxdc_resend --- src/peer_channels.rs | 46 ++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/peer_channels.rs b/src/peer_channels.rs index 7ace08fc9..53d37927d 100644 --- a/src/peer_channels.rs +++ b/src/peer_channels.rs @@ -990,23 +990,41 @@ mod tests { alice.recv_msg_trash(&fiona_advert).await; fiona_connect_future.await.unwrap(); - send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into()) - .await - .unwrap(); - loop { - let event = fiona.evtracker.recv().await.unwrap(); - if let EventType::WebxdcRealtimeData { data, .. } = event.typ { - if data == b"alice -> bob & fiona" { - break; - } else { - panic!( - "Unexpected status update: {}", - String::from_utf8_lossy(&data) - ); + let realtime_send_loop = async { + // Keep sending in a loop because right after joining + // Fiona may miss messages. + loop { + send_webxdc_realtime_data(alice, instance.id, b"alice -> bob & fiona".into()) + .await + .unwrap(); + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + } + }; + + let realtime_receive_loop = async { + loop { + let event = fiona.evtracker.recv().await.unwrap(); + if let EventType::WebxdcRealtimeData { data, .. } = event.typ { + if data == b"alice -> bob & fiona" { + break; + } else { + panic!( + "Unexpected status update: {}", + String::from_utf8_lossy(&data) + ); + } } } - } + }; + tokio::select!( + _ = realtime_send_loop => { + panic!("Send loop should never finish"); + }, + _ = realtime_receive_loop => { + return; + } + ); } async fn connect_alice_bob(