Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure many batches are able to be imported (MSC2716) #212

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to assert the number of events returned too, and that they have different event IDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Going to close this one in favor of #214 which actually checks for all of the messages in the batches

"dir": []string{"b"},
"limit": []string{"100"},
}))
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this down one more test


t.Run("Historical events from multiple users in the same batch", func(t *testing.T) {
t.Parallel()

Expand Down