@@ -1150,6 +1150,66 @@ func TestPartialStateJoin(t *testing.T) {
1150
1150
t .Errorf ("SendJoin: non-HTTPError: %v" , err )
1151
1151
}
1152
1152
})
1153
+
1154
+ // test that a /joined_members request made during a partial-state /send_join
1155
+ // request blocks until the state is correctly synced.
1156
+ t .Run ("joined_members blocks during partial state join" , func (t * testing.T ) {
1157
+ deployment := Deploy (t , b .BlueprintAlice )
1158
+ defer deployment .Destroy (t )
1159
+ alice := deployment .Client (t , "hs1" , "@alice:hs1" )
1160
+
1161
+ server := createTestServer (t , deployment )
1162
+ cancel := server .Listen ()
1163
+ defer cancel ()
1164
+ serverRoom := createTestRoom (t , server , alice .GetDefaultRoomVersion (t ))
1165
+ psjResult := beginPartialStateJoin (t , server , serverRoom , alice )
1166
+ defer psjResult .Destroy ()
1167
+
1168
+ // Alice has now joined the room, and the server is syncing the state in the background.
1169
+
1170
+ // attempts to sync should now block. Fire off a goroutine to try it.
1171
+ jmResponseChan := make (chan * http.Response )
1172
+ defer close (jmResponseChan )
1173
+ go func () {
1174
+ response := alice .MustDoFunc (t , "GET" , []string {"_matrix" , "client" , "v3" , "rooms" , serverRoom .RoomID , "joined_members" })
1175
+ jmResponseChan <- response
1176
+ }()
1177
+
1178
+ // wait for the state_ids request to arrive
1179
+ psjResult .AwaitStateIdsRequest (t )
1180
+
1181
+ // the client-side requests should still be waiting
1182
+ select {
1183
+ case <- jmResponseChan :
1184
+ t .Fatalf ("/joined_members completed before state resync complete. Expected it to block." )
1185
+ default :
1186
+ }
1187
+
1188
+ // release the federation /state response
1189
+ psjResult .FinishStateRequest ()
1190
+
1191
+ // the /joined_members request should now complete, with the new room
1192
+ var jmRes * http.Response
1193
+ select {
1194
+ case <- time .After (1 * time .Second ):
1195
+ t .Fatalf ("/joined_members request request did not complete. Expected it to complete." )
1196
+ case jmRes = <- jmResponseChan :
1197
+ }
1198
+
1199
+ derekUserID := client .GjsonEscape (server .UserID ("derek" ))
1200
+
1201
+ must .MatchResponse (t , jmRes , match.HTTPResponse {
1202
+ JSON : []match.JSON {
1203
+ match .JSONKeyPresent ("joined" ),
1204
+ match .JSONKeyPresent ("joined." + alice .UserID ),
1205
+ match .JSONKeyPresent ("joined." + alice .UserID + ".display_name" ),
1206
+ match .JSONKeyPresent ("joined." + alice .UserID + ".avatar_url" ),
1207
+ match .JSONKeyPresent ("joined." + derekUserID ),
1208
+ match .JSONKeyPresent ("joined." + derekUserID + ".display_name" ),
1209
+ match .JSONKeyPresent ("joined." + derekUserID + ".avatar_url" ),
1210
+ },
1211
+ })
1212
+ })
1153
1213
}
1154
1214
1155
1215
// test reception of an event over federation during a resync
0 commit comments