Skip to content

Commit 2180cc5

Browse files
Add test for non-member state events in /batch_send state_events_at_start (#354)
Tests for matrix-org/synapse#12110 Synapse change: matrix-org/synapse#12329
1 parent 4eea371 commit 2180cc5

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

tests/msc2716_test.go

+59-40
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,47 @@ func TestImportHistoricalMessages(t *testing.T) {
306306
}
307307
})
308308

309+
t.Run("Non-member state events are allowed in state_events_at_start", func(t *testing.T) {
310+
t.Parallel()
311+
312+
roomID := as.CreateRoom(t, createPublicRoomOpts)
313+
alice.JoinRoom(t, roomID, nil)
314+
315+
// Create the "live" event we are going to insert our historical events next to
316+
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
317+
eventIdBefore := eventIDsBefore[0]
318+
timeAfterEventBefore := time.Now()
319+
320+
stateEventsAtStart := createJoinStateEventsForBatchSendRequest([]string{virtualUserID}, timeAfterEventBefore)
321+
// Add the non-member state
322+
stateEventsAtStart = append(stateEventsAtStart, map[string]interface{}{
323+
"type": "org.matrix.msc2716.foobarbaz",
324+
"sender": as.UserID,
325+
"origin_server_ts": uint64(timeAfterEventBefore.UnixNano() / int64(time.Millisecond)),
326+
"content": map[string]interface{}{
327+
"foo": "bar",
328+
},
329+
"state_key": "",
330+
})
331+
332+
batchSendRes := batchSendHistoricalMessages(
333+
t,
334+
as,
335+
roomID,
336+
eventIdBefore,
337+
"",
338+
stateEventsAtStart,
339+
createMessageEventsForBatchSendRequest([]string{virtualUserID}, timeAfterEventBefore, 1),
340+
// Status
341+
200,
342+
)
343+
validateBatchSendRes(
344+
t, as, roomID, batchSendRes,
345+
// Validate that the non-member state resolves
346+
true,
347+
)
348+
})
349+
309350
t.Run("Unrecognised prev_event ID will throw an error", func(t *testing.T) {
310351
t.Parallel()
311352

@@ -1342,37 +1383,30 @@ func validateBatchSendRes(t *testing.T, c *client.CSAPI, roomID string, batchSen
13421383
expectedEventIDOrder = append(expectedEventIDOrder, reversed(historicalEventIDs)...)
13431384
expectedEventIDOrder = append(expectedEventIDOrder, insertionEventID)
13441385

1386+
// Make sure the historical events appear in scrollback without jumping back
1387+
// in time specifically.
1388+
fullMessagesRes := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
1389+
"dir": []string{"b"},
1390+
"limit": []string{"100"},
1391+
}))
1392+
must.MatchResponse(t, fullMessagesRes, match.HTTPResponse{
1393+
JSON: []match.JSON{
1394+
matcherJSONEventIDArrayInOrder("chunk",
1395+
expectedEventIDOrder,
1396+
historicalEventFilter,
1397+
),
1398+
},
1399+
})
1400+
1401+
// Validate state after we paginate `/messages` to avoid any potential 404 if
1402+
// the server hasn't backfilled here yet
13451403
if validateState {
1346-
// Get a pagination token for the newest-in-time event in the historical batch itself
13471404
contextRes := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", expectedEventIDOrder[0]}, client.WithContentType("application/json"), client.WithQueries(url.Values{
13481405
"limit": []string{"0"},
13491406
}))
1350-
contextResBody := client.ParseJSON(t, contextRes)
1351-
batchStartPaginationToken := client.GetJSONFieldStr(t, contextResBody, "end")
1352-
1353-
// Fetch a chunk of `/messages` which only contains the historical batch. We
1354-
// want to do this because `/messages` only returns the state for the first
1355-
// message in the `chunk` and we want to be able assert that the historical
1356-
// state is able to be resolved.
1357-
messagesRes := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
1358-
// Go backwards (newest -> oldest) (same direction as if you were using scrollback)
1359-
"dir": []string{"b"},
1360-
// From the newest-in-time event in the historical batch
1361-
"from": []string{batchStartPaginationToken},
1362-
// We are aiming to scrollback to the oldest-in-time event from the
1363-
// historical batch
1364-
"limit": []string{fmt.Sprintf("%d", len(expectedEventIDOrder))},
1365-
// We add these options to the filter so we get member events in the state field
1366-
"filter": []string{"{\"lazy_load_members\":true,\"include_redundant_members\":true}"},
1367-
}))
13681407

1369-
must.MatchResponse(t, messagesRes, match.HTTPResponse{
1408+
must.MatchResponse(t, contextRes, match.HTTPResponse{
13701409
JSON: []match.JSON{
1371-
// Double-check that we're in the right place of scrollback
1372-
matcherJSONEventIDArrayInOrder("chunk",
1373-
expectedEventIDOrder,
1374-
historicalEventFilter,
1375-
),
13761410
// Make sure the historical m.room.member join state event resolves
13771411
// for the given chunk of messages in scrollback. The member event
13781412
// will include the displayname and avatar.
@@ -1382,21 +1416,6 @@ func validateBatchSendRes(t *testing.T, c *client.CSAPI, roomID string, batchSen
13821416
},
13831417
})
13841418
}
1385-
1386-
// Make sure the historical events appear in scrollback without jumping back
1387-
// in time specifically.
1388-
fullMessagesRes := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
1389-
"dir": []string{"b"},
1390-
"limit": []string{"100"},
1391-
}))
1392-
must.MatchResponse(t, fullMessagesRes, match.HTTPResponse{
1393-
JSON: []match.JSON{
1394-
matcherJSONEventIDArrayInOrder("chunk",
1395-
expectedEventIDOrder,
1396-
historicalEventFilter,
1397-
),
1398-
},
1399-
})
14001419
}
14011420

14021421
// matcherJSONEventIDArrayInOrder loops through `jsonArrayKey` in the response

0 commit comments

Comments
 (0)