@@ -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 {
@@ -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 {
@@ -600,11 +612,21 @@ Here's my footer -- bob@example.net"
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
+ error ! ( t, "Unwanted event: {ev:?}." ) ;
628
+ unreachable ! ( )
629
+ }
608
630
}
609
631
610
632
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
@@ -635,9 +657,10 @@ Here's my footer -- bob@example.net"
635
657
636
658
bob_msg. chat_id . accept ( & bob) . await ?;
637
659
660
+ bob. evtracker . clear_events ( ) ;
638
661
send_reaction ( & bob, bob_msg. id , "👍" ) . await . unwrap ( ) ;
639
662
expect_reactions_changed_event ( & bob, bob_msg. chat_id , bob_msg. id , ContactId :: SELF ) . await ?;
640
- assert ! ( !has_incoming_reactions_event ( & bob) . await ) ;
663
+ expect_no_unwanted_events ( & bob) . await ;
641
664
assert_eq ! ( get_chat_msgs( & bob, bob_msg. chat_id) . await ?. len( ) , 2 ) ;
642
665
643
666
let bob_reaction_msg = bob. pop_sent_msg ( ) . await ;
@@ -656,6 +679,7 @@ Here's my footer -- bob@example.net"
656
679
expect_reactions_changed_event ( & alice, chat_alice. id , alice_msg. sender_msg_id , * bob_id)
657
680
. await ?;
658
681
expect_incoming_reactions_event ( & alice, alice_msg. sender_msg_id , * bob_id, "👍" ) . await ?;
682
+ expect_no_unwanted_events ( & alice) . await ;
659
683
660
684
// Alice reacts to own message.
661
685
send_reaction ( & alice, alice_msg. sender_msg_id , "👍 😀" )
@@ -684,6 +708,7 @@ Here's my footer -- bob@example.net"
684
708
let bob = TestContext :: new_bob ( ) . await ;
685
709
alice. set_config ( Config :: Displayname , Some ( "ALICE" ) ) . await ?;
686
710
bob. set_config ( Config :: Displayname , Some ( "BOB" ) ) . await ?;
711
+ let alice_bob_id = alice. add_or_lookup_contact_id ( & bob) . await ;
687
712
688
713
// Alice sends message to Bob
689
714
let alice_chat = alice. create_chat ( & bob) . await ;
@@ -696,7 +721,9 @@ Here's my footer -- bob@example.net"
696
721
send_reaction ( & bob, bob_msg1. id , "👍" ) . await ?;
697
722
let bob_send_reaction = bob. pop_sent_msg ( ) . await ;
698
723
alice. recv_msg_trash ( & bob_send_reaction) . await ;
699
- assert ! ( has_incoming_reactions_event( & alice) . await ) ;
724
+ expect_incoming_reactions_event ( & alice, alice_msg1. sender_msg_id , alice_bob_id, "👍" )
725
+ . await ?;
726
+ expect_no_unwanted_events ( & alice) . await ;
700
727
701
728
let chatlist = Chatlist :: try_load ( & bob, 0 , None , None ) . await ?;
702
729
let summary = chatlist. get_summary ( & bob, 0 , None ) . await ?;
@@ -711,8 +738,9 @@ Here's my footer -- bob@example.net"
711
738
SystemTime :: shift ( Duration :: from_secs ( 10 ) ) ;
712
739
send_reaction ( & alice, alice_msg1. sender_msg_id , "🍿" ) . await ?;
713
740
let alice_send_reaction = alice. pop_sent_msg ( ) . await ;
741
+ bob. evtracker . clear_events ( ) ;
714
742
bob. recv_msg_opt ( & alice_send_reaction) . await ;
715
- assert ! ( !has_incoming_reactions_event ( & bob) . await ) ;
743
+ expect_no_unwanted_events ( & bob) . await ;
716
744
717
745
assert_summary ( & alice, "You reacted 🍿 to \" Party?\" " ) . await ;
718
746
assert_summary ( & bob, "ALICE reacted 🍿 to \" Party?\" " ) . await ;
@@ -934,7 +962,9 @@ Here's my footer -- bob@example.net"
934
962
expect_reactions_changed_event ( & alice0, chat_id, alice0_msg_id, ContactId :: SELF ) . await ?;
935
963
expect_reactions_changed_event ( & alice1, alice1_msg. chat_id , alice1_msg. id , ContactId :: SELF )
936
964
. await ?;
937
-
965
+ for a in [ & alice0, & alice1] {
966
+ expect_no_unwanted_events ( a) . await ;
967
+ }
938
968
Ok ( ( ) )
939
969
}
940
970
}
0 commit comments