diff --git a/tests/msc2716_test.go b/tests/msc2716_test.go index 0ad694ca..6251201c 100644 --- a/tests/msc2716_test.go +++ b/tests/msc2716_test.go @@ -207,6 +207,54 @@ func TestImportHistoricalMessages(t *testing.T) { } }) + t.Run("Many batches are able to be imported and recalled from /messages", func(t *testing.T) { + t.Parallel() + + roomID := as.CreateRoom(t, createPublicRoomOpts) + alice.JoinRoom(t, roomID, nil) + + // Create some normal messages in the timeline + eventIDsBefore := createMessagesInRoom(t, alice, roomID, 2) + eventIdBefore := eventIDsBefore[len(eventIDsBefore)-1] + timeAfterEventBefore := time.Now() + + // wait X number of ms to ensure that the timestamp changes enough for + // each of the historical messages we try to import later + numBatches := 11 + numHistoricalMessagesPerBatch := 100 + time.Sleep(time.Duration(numBatches*numHistoricalMessagesPerBatch) * timeBetweenMessages) + + // eventIDsAfter + createMessagesInRoom(t, alice, roomID, 2) + + // Import a long chain of batches connected to each other. + // We want to make sure Synapse doesn't blow up after we import + // many messages. + nextBatchID := "" + for i := 0; i < numBatches; i++ { + insertTime := timeAfterEventBefore.Add(timeBetweenMessages * time.Duration(numBatches-numHistoricalMessagesPerBatch*i)) + batchSendRes := batchSendHistoricalMessages( + t, + as, + roomID, + eventIdBefore, + nextBatchID, + createJoinStateEventsForBatchSendRequest([]string{virtualUserID}, insertTime), + createMessageEventsForBatchSendRequest([]string{virtualUserID}, insertTime, numHistoricalMessagesPerBatch), + // Status + 200, + ) + batchSendResBody := client.ParseJSON(t, batchSendRes) + nextBatchID = client.GetJSONFieldStr(t, batchSendResBody, "next_batch_id") + } + + // Ensure the /message response gives a 200 + alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ + "dir": []string{"b"}, + "limit": []string{"100"}, + })) + }) + t.Run("Historical events from multiple users in the same batch", func(t *testing.T) { t.Parallel()