Skip to content

Commit

Permalink
Add messageSuffix to more easily spot which message is which when deb…
Browse files Browse the repository at this point in the history
…ugging (#251)

Split off from #214
  • Loading branch information
MadLittleMods authored Jan 13, 2022
1 parent 241cbb6 commit b638ca2
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestImportHistoricalMessages(t *testing.T) {
//
// Create the first batch including the "live" event we are going to
// import our historical events next to.
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 2)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 2, "eventIDsBefore")
eventIdBefore := eventIDsBefore[len(eventIDsBefore)-1]
timeAfterEventBefore := time.Now()

Expand All @@ -111,7 +111,7 @@ func TestImportHistoricalMessages(t *testing.T) {
// Create the second batch of events.
// This will also fill up the buffer so we have to scrollback to the
// inserted history later.
eventIDsAfter := createMessagesInRoom(t, alice, roomID, 2)
eventIDsAfter := createMessagesInRoom(t, alice, roomID, 2, "eventIDsAfter")

// Insert the most recent batch of historical messages
insertTime0 := timeAfterEventBefore.Add(timeBetweenMessages * 3)
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to insert our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -227,12 +227,12 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to insert our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

// Create some "live" events to saturate and fill up the /sync response
createMessagesInRoom(t, alice, roomID, 5)
createMessagesInRoom(t, alice, roomID, 5, "live")

// Get a /sync `since` pagination token we can try paginating from later
// on
Expand All @@ -255,7 +255,7 @@ func TestImportHistoricalMessages(t *testing.T) {
historicalStateEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "state_event_ids")

// This is just a dummy event we search for after the historicalEventIDs/historicalStateEventIDs
eventIDsAfterHistoricalImport := createMessagesInRoom(t, alice, roomID, 1)
eventIDsAfterHistoricalImport := createMessagesInRoom(t, alice, roomID, 1, "eventIDsAfterHistoricalImport")
eventIDAfterHistoricalImport := eventIDsAfterHistoricalImport[0]

// Sync from before we did any batch sending until we find the
Expand All @@ -279,7 +279,7 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to import our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -333,7 +333,7 @@ func TestImportHistoricalMessages(t *testing.T) {
roomID := as.CreateRoom(t, createPublicRoomOpts)
alice.JoinRoom(t, roomID, nil)

eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -387,7 +387,7 @@ func TestImportHistoricalMessages(t *testing.T) {
roomID := as.CreateRoom(t, createPublicRoomOpts)
alice.JoinRoom(t, roomID, nil)

eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -418,7 +418,7 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to import our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -457,12 +457,11 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to insert our backfilled events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

// eventIDsAfter
createMessagesInRoom(t, alice, roomID, 2)
createMessagesInRoom(t, alice, roomID, 2, "eventIDsAfter")

// Import a batch of historical events
batchSendRes0 := batchSendHistoricalMessages(
Expand Down Expand Up @@ -517,7 +516,7 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to import our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -556,12 +555,11 @@ func TestImportHistoricalMessages(t *testing.T) {
roomID := as.CreateRoom(t, createPublicRoomOpts)
alice.JoinRoom(t, roomID, nil)

eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

// eventIDsAfter
createMessagesInRoom(t, alice, roomID, 3)
createMessagesInRoom(t, alice, roomID, 3, "eventIDsAfter")

batchSendRes := batchSendHistoricalMessages(
t,
Expand Down Expand Up @@ -620,7 +618,7 @@ func TestImportHistoricalMessages(t *testing.T) {
roomID := as.CreateRoom(t, createPublicRoomOpts)
alice.JoinRoom(t, roomID, nil)

eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand All @@ -643,8 +641,7 @@ func TestImportHistoricalMessages(t *testing.T) {
return ev.Get("event_id").Str == insertionEventID
}))

// eventIDsAfter
createMessagesInRoom(t, alice, roomID, 3)
createMessagesInRoom(t, alice, roomID, 3, "eventIDsAfter")

batchSendRes := batchSendHistoricalMessages(
t,
Expand Down Expand Up @@ -705,12 +702,11 @@ func TestImportHistoricalMessages(t *testing.T) {
// Join the room from a remote homeserver before any historical messages are sent
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})

eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

// eventIDsAfter
createMessagesInRoom(t, alice, roomID, 10)
createMessagesInRoom(t, alice, roomID, 10, "eventIDsAfter")

// Mimic scrollback just through the latest messages
remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
Expand Down Expand Up @@ -800,12 +796,11 @@ func TestImportHistoricalMessages(t *testing.T) {
// Join the room from a remote homeserver before any historical messages are sent
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})

eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

// eventIDsAfter
createMessagesInRoom(t, alice, roomID, 3)
createMessagesInRoom(t, alice, roomID, 3, "eventIDsAfter")

// Mimic scrollback to all of the messages
// scrollbackMessagesRes
Expand Down Expand Up @@ -901,12 +896,12 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to import our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

// Create eventIDsAfter to avoid the "No forward extremities left!" 500 error from Synapse
createMessagesInRoom(t, alice, roomID, 2)
createMessagesInRoom(t, alice, roomID, 2, "eventIDsAfter")

// Import a historical event
batchSendRes := batchSendHistoricalMessages(
Expand Down Expand Up @@ -951,7 +946,7 @@ func TestImportHistoricalMessages(t *testing.T) {
alice.JoinRoom(t, roomID, nil)

// Create the "live" event we are going to import our historical events next to
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1)
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
eventIdBefore := eventIDsBefore[0]
timeAfterEventBefore := time.Now()

Expand Down Expand Up @@ -1159,14 +1154,14 @@ func sendMarkerAndEnsureBackfilled(t *testing.T, as *client.CSAPI, c *client.CSA
return markerEventID
}

func createMessagesInRoom(t *testing.T, c *client.CSAPI, roomID string, count int) (eventIDs []string) {
func createMessagesInRoom(t *testing.T, c *client.CSAPI, roomID string, count int, messageSuffix string) (eventIDs []string) {
eventIDs = make([]string, count)
for i := 0; i < len(eventIDs); i++ {
newEvent := b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": fmt.Sprintf("Message %d", i),
"body": fmt.Sprintf("Message %d (%s)", i, messageSuffix),
},
}
newEventId := c.SendEventSynced(t, roomID, newEvent)
Expand Down

0 comments on commit b638ca2

Please sign in to comment.