@@ -826,21 +826,31 @@ func TestLeaveReinviteSyncFederated(t *testing.T) {
826826
827827 alice := deployment .Register (t , "hs1" , helpers.RegistrationOpts {})
828828 bob := deployment .Register (t , "hs2" , helpers.RegistrationOpts {})
829+
830+ // Charlie is simply here to flag when events arrive over federation to hs2.
831+ charlie := deployment .Register (t , "hs2" , helpers.RegistrationOpts {})
829832
830- // 1. Alice creates a room and Bob joins
833+ // 1. Alice creates a room and both Bob and Charlie join
831834 roomID := alice .MustCreateRoom (t , map [string ]any {
832835 "preset" : "public_chat" ,
833836 })
834837
835- // Bob needs to join via federation, so we need to specify the server name
838+ // Users on hs2 need to join via federation, so we need to specify the server name
836839 alice .MustInviteRoom (t , roomID , bob .UserID )
840+ alice .MustInviteRoom (t , roomID , charlie .UserID )
837841 bob .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob .UserID , roomID ))
842+ charlie .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (charlie .UserID , roomID ))
843+
838844 bob .MustJoinRoom (t , roomID , []spec.ServerName {
839845 deployment .GetFullyQualifiedHomeserverName (t , "hs1" ),
840846 })
847+ charlie .MustJoinRoom (t , roomID , []spec.ServerName {
848+ deployment .GetFullyQualifiedHomeserverName (t , "hs1" ),
849+ })
841850
842- // 2. Bob does a sync and verifies they see the join
851+ // 2. Both Bob and Charlie do a sync and verify that they see the join
843852 bobSince := bob .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (bob .UserID , roomID ))
853+ charlieSince := charlie .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (charlie .UserID , roomID ))
844854
845855 // 3. Alice kicks Bob from the room and then re-invites them.
846856 // For kicking, we need to use the POST /rooms/{roomId}/kick endpoint
@@ -851,12 +861,20 @@ func TestLeaveReinviteSyncFederated(t *testing.T) {
851861 )
852862
853863 // Wait until Bob is kicked.
854- alice .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (bob .UserID , roomID ))
864+ aliceSince := alice .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (bob .UserID , roomID ))
865+ charlieSince = charlie .MustSyncUntil (t , client.SyncReq {Since : charlieSince }, client .SyncLeftFrom (bob .UserID , roomID ))
855866
856867 // Alice re-invites Bob
857868 alice .MustInviteRoom (t , roomID , bob .UserID )
858-
859- // 4. Bob does a sync
869+ alice .MustSyncUntil (t , client.SyncReq {Since : aliceSince }, client .SyncInvitedTo (bob .UserID , roomID ))
870+
871+ // Wait until hs2 sees that Bob has been kicked and re-invited (this is all
872+ // Charlie is needed for). If we don't wait, then Bob might sync too early
873+ // (slow federation) and catch the kick in one sync iteration, and the
874+ // invite in another, invalidating the test conditions.
875+ charlieSince = charlie .MustSyncUntil (t , client.SyncReq {Since : charlieSince }, client .SyncInvitedTo (bob .UserID , roomID ))
876+
877+ // 4. Bob does an incremental sync. Bob's last sync was after they joined the room.
860878 jsonRes , _ := bob .MustSync (t , client.SyncReq {Since : bobSince })
861879
862880 // Bob should only see an invite, not both an invite and a leave event
0 commit comments