@@ -558,7 +558,12 @@ Here's my footer -- bob@example.net"
558
558
) -> Result < ( ) > {
559
559
let event = t
560
560
. evtracker
561
- . get_matching ( |evt| matches ! ( evt, EventType :: ReactionsChanged { .. } ) )
561
+ . get_matching ( |evt| {
562
+ matches ! (
563
+ evt,
564
+ EventType :: ReactionsChanged { .. } | EventType :: IncomingMsg { .. }
565
+ )
566
+ } )
562
567
. await ;
563
568
match event {
564
569
EventType :: ReactionsChanged {
@@ -570,7 +575,7 @@ Here's my footer -- bob@example.net"
570
575
assert_eq ! ( msg_id, expected_msg_id) ;
571
576
assert_eq ! ( contact_id, expected_contact_id) ;
572
577
}
573
- _ => unreachable ! ( ) ,
578
+ _ => panic ! ( "Unexpected event {event:?}." ) ,
574
579
}
575
580
Ok ( ( ) )
576
581
}
@@ -583,7 +588,14 @@ Here's my footer -- bob@example.net"
583
588
) -> Result < ( ) > {
584
589
let event = t
585
590
. evtracker
586
- . get_matching ( |evt| matches ! ( evt, EventType :: IncomingReaction { .. } ) )
591
+ // Check for absence of `IncomingMsg` events -- it appeared that it's quite easy to make
592
+ // bugs when `IncomingMsg` is issued for reactions.
593
+ . get_matching ( |evt| {
594
+ matches ! (
595
+ evt,
596
+ EventType :: IncomingReaction { .. } | EventType :: IncomingMsg { .. }
597
+ )
598
+ } )
587
599
. await ;
588
600
match event {
589
601
EventType :: IncomingReaction {
@@ -595,16 +607,25 @@ Here's my footer -- bob@example.net"
595
607
assert_eq ! ( contact_id, expected_contact_id) ;
596
608
assert_eq ! ( reaction, Reaction :: from( expected_reaction) ) ;
597
609
}
598
- _ => unreachable ! ( ) ,
610
+ _ => panic ! ( "Unexpected event {event:?}." ) ,
599
611
}
600
612
Ok ( ( ) )
601
613
}
602
614
603
- async fn has_incoming_reactions_event ( t : & TestContext ) -> bool {
604
- t. evtracker
605
- . get_matching_opt ( t, |evt| matches ! ( evt, EventType :: IncomingReaction { .. } ) )
606
- . await
607
- . is_some ( )
615
+ /// Checks that no unwanted events remain after expecting "wanted" reaction events.
616
+ async fn expect_no_unwanted_events ( t : & TestContext ) {
617
+ let ev = t
618
+ . evtracker
619
+ . get_matching_opt ( t, |evt| {
620
+ matches ! (
621
+ evt,
622
+ EventType :: IncomingReaction { .. } | EventType :: IncomingMsg { .. }
623
+ )
624
+ } )
625
+ . await ;
626
+ if let Some ( ev) = ev {
627
+ panic ! ( "Unwanted event {ev:?}." )
628
+ }
608
629
}
609
630
610
631
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
@@ -635,9 +656,10 @@ Here's my footer -- bob@example.net"
635
656
636
657
bob_msg. chat_id . accept ( & bob) . await ?;
637
658
659
+ bob. evtracker . clear_events ( ) ;
638
660
send_reaction ( & bob, bob_msg. id , "👍" ) . await . unwrap ( ) ;
639
661
expect_reactions_changed_event ( & bob, bob_msg. chat_id , bob_msg. id , ContactId :: SELF ) . await ?;
640
- assert ! ( !has_incoming_reactions_event ( & bob) . await ) ;
662
+ expect_no_unwanted_events ( & bob) . await ;
641
663
assert_eq ! ( get_chat_msgs( & bob, bob_msg. chat_id) . await ?. len( ) , 2 ) ;
642
664
643
665
let bob_reaction_msg = bob. pop_sent_msg ( ) . await ;
@@ -656,6 +678,7 @@ Here's my footer -- bob@example.net"
656
678
expect_reactions_changed_event ( & alice, chat_alice. id , alice_msg. sender_msg_id , * bob_id)
657
679
. await ?;
658
680
expect_incoming_reactions_event ( & alice, alice_msg. sender_msg_id , * bob_id, "👍" ) . await ?;
681
+ expect_no_unwanted_events ( & alice) . await ;
659
682
660
683
// Alice reacts to own message.
661
684
send_reaction ( & alice, alice_msg. sender_msg_id , "👍 😀" )
@@ -684,6 +707,7 @@ Here's my footer -- bob@example.net"
684
707
let bob = TestContext :: new_bob ( ) . await ;
685
708
alice. set_config ( Config :: Displayname , Some ( "ALICE" ) ) . await ?;
686
709
bob. set_config ( Config :: Displayname , Some ( "BOB" ) ) . await ?;
710
+ let alice_bob_id = alice. add_or_lookup_contact_id ( & bob) . await ;
687
711
688
712
// Alice sends message to Bob
689
713
let alice_chat = alice. create_chat ( & bob) . await ;
@@ -696,7 +720,9 @@ Here's my footer -- bob@example.net"
696
720
send_reaction ( & bob, bob_msg1. id , "👍" ) . await ?;
697
721
let bob_send_reaction = bob. pop_sent_msg ( ) . await ;
698
722
alice. recv_msg_trash ( & bob_send_reaction) . await ;
699
- assert ! ( has_incoming_reactions_event( & alice) . await ) ;
723
+ expect_incoming_reactions_event ( & alice, alice_msg1. sender_msg_id , alice_bob_id, "👍" )
724
+ . await ?;
725
+ expect_no_unwanted_events ( & alice) . await ;
700
726
701
727
let chatlist = Chatlist :: try_load ( & bob, 0 , None , None ) . await ?;
702
728
let summary = chatlist. get_summary ( & bob, 0 , None ) . await ?;
@@ -711,8 +737,9 @@ Here's my footer -- bob@example.net"
711
737
SystemTime :: shift ( Duration :: from_secs ( 10 ) ) ;
712
738
send_reaction ( & alice, alice_msg1. sender_msg_id , "🍿" ) . await ?;
713
739
let alice_send_reaction = alice. pop_sent_msg ( ) . await ;
740
+ bob. evtracker . clear_events ( ) ;
714
741
bob. recv_msg_opt ( & alice_send_reaction) . await ;
715
- assert ! ( !has_incoming_reactions_event ( & bob) . await ) ;
742
+ expect_no_unwanted_events ( & bob) . await ;
716
743
717
744
assert_summary ( & alice, "You reacted 🍿 to \" Party?\" " ) . await ;
718
745
assert_summary ( & bob, "ALICE reacted 🍿 to \" Party?\" " ) . await ;
@@ -934,7 +961,9 @@ Here's my footer -- bob@example.net"
934
961
expect_reactions_changed_event ( & alice0, chat_id, alice0_msg_id, ContactId :: SELF ) . await ?;
935
962
expect_reactions_changed_event ( & alice1, alice1_msg. chat_id , alice1_msg. id , ContactId :: SELF )
936
963
. await ?;
937
-
964
+ for a in [ & alice0, & alice1] {
965
+ expect_no_unwanted_events ( a) . await ;
966
+ }
938
967
Ok ( ( ) )
939
968
}
940
969
}
0 commit comments