@@ -4,15 +4,13 @@ import (
44 "net/http"
55 "net/url"
66 "testing"
7- "time"
87
98 "github.com/tidwall/gjson"
109
1110 "github.com/matrix-org/complement/internal/b"
1211 "github.com/matrix-org/complement/internal/client"
1312 "github.com/matrix-org/complement/internal/match"
1413 "github.com/matrix-org/complement/internal/must"
15- "github.com/matrix-org/complement/runtime"
1614)
1715
1816// These tests ensure that forgetting about rooms works as intended
@@ -70,22 +68,29 @@ func TestRoomForget(t *testing.T) {
7068 },
7169 })
7270 alice .LeaveRoom (t , roomID )
71+ // Ensure Alice left the room
72+ bob .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (alice .UserID , roomID ))
7373 alice .MustDoFunc (t , "POST" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "forget" })
74- time .Sleep (50 * time .Millisecond )
74+ bob .SendEventSynced (t , roomID , b.Event {
75+ Type : "m.room.message" ,
76+ Content : map [string ]interface {}{
77+ "msgtype" : "m.text" ,
78+ "body" : "Hello world!" ,
79+ },
80+ })
7581 result , _ := alice .MustSync (t , client.SyncReq {})
76- if result .Get ("rooms.archived" ). Get (roomID ).Exists () {
77- t .Errorf ("Did not expect room in archived" )
82+ if result .Get ("rooms.archived." + client . GjsonEscape (roomID ) ).Exists () {
83+ t .Errorf ("Did not expect room %s in archived" , roomID )
7884 }
79- if result .Get ("rooms.join" ). Get (roomID ).Exists () {
80- t .Errorf ("Did not expect room in joined" )
85+ if result .Get ("rooms.join." + client . GjsonEscape (roomID ) ).Exists () {
86+ t .Errorf ("Did not expect room %s in joined" , roomID )
8187 }
82- if result .Get ("rooms.invite" ). Get (roomID ).Exists () {
83- t .Errorf ("Did not expect room in invited" )
88+ if result .Get ("rooms.invite." + client . GjsonEscape (roomID ) ).Exists () {
89+ t .Errorf ("Did not expect room %s in invited" , roomID )
8490 }
8591 })
8692 // sytest: Can forget room you've been kicked from
8793 t .Run ("Can forget room you've been kicked from" , func (t * testing.T ) {
88- runtime .SkipIf (t , runtime .Dendrite ) // flakey
8994 t .Parallel ()
9095 roomID := alice .CreateRoom (t , map [string ]interface {}{"preset" : "public_chat" })
9196 bob .JoinRoom (t , roomID , []string {})
@@ -102,16 +107,17 @@ func TestRoomForget(t *testing.T) {
102107 "user_id" : bob .UserID ,
103108 }),
104109 )
105- time .Sleep (50 * time .Millisecond )
110+ // Ensure Bob was really kicked
111+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (bob .UserID , roomID ))
106112 result , _ := bob .MustSync (t , client.SyncReq {})
107- if result .Get ("rooms.archived" ). Get (roomID ).Exists () {
108- t .Errorf ("Did not expect room in archived" )
113+ if result .Get ("rooms.archived." + client . GjsonEscape (roomID ) ).Exists () {
114+ t .Errorf ("Did not expect room %s in archived" , roomID )
109115 }
110- if result .Get ("rooms.join" ). Get (roomID ).Exists () {
111- t .Errorf ("Did not expect room in joined" )
116+ if result .Get ("rooms.join." + client . GjsonEscape (roomID ) ).Exists () {
117+ t .Errorf ("Did not expect room %s in joined" , roomID )
112118 }
113- if result .Get ("rooms.invite" ). Get (roomID ).Exists () {
114- t .Errorf ("Did not expect room in invited" )
119+ if result .Get ("rooms.invite." + client . GjsonEscape (roomID ) ).Exists () {
120+ t .Errorf ("Did not expect room %s in invited" , roomID )
115121 }
116122 })
117123
@@ -139,6 +145,8 @@ func TestRoomForget(t *testing.T) {
139145 })
140146 // Bob leaves and forgets room
141147 bob .LeaveRoom (t , roomID )
148+ // Ensure Bob has really left the room
149+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (bob .UserID , roomID ))
142150 bob .MustDoFunc (t , "POST" , []string {"_matrix" , "client" , "r0" , "rooms" , roomID , "forget" })
143151 // Try to re-join
144152 joinRes := bob .DoFunc (t , "POST" , []string {"_matrix" , "client" , "r0" , "join" , roomID })
0 commit comments