@@ -990,23 +990,41 @@ mod tests {
990
990
alice. recv_msg_trash ( & fiona_advert) . await ;
991
991
992
992
fiona_connect_future. await . unwrap ( ) ;
993
- send_webxdc_realtime_data ( alice, instance. id , b"alice -> bob & fiona" . into ( ) )
994
- . await
995
- . unwrap ( ) ;
996
993
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
+ }
1007
1017
}
1008
1018
}
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
+ ) ;
1010
1028
}
1011
1029
1012
1030
async fn connect_alice_bob (
0 commit comments