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

Rename MSC2716 things from chunk to batch to match /batch_send endpoint #205

Merged
merged 28 commits into from
Sep 21, 2021
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
048887b
Update MSC2716 federation test cases
MadLittleMods Jul 23, 2021
d385044
Uncomment some federated test cases
MadLittleMods Jul 26, 2021
493f7ea
Merge branch 'master' into madlittlemods/msc2716-federation-changes
MadLittleMods Jul 29, 2021
faec5ca
More proper waiting to avoid flakey test
MadLittleMods Jul 29, 2021
edade9c
Get both tests working and de-duplicate marker sending verifying
MadLittleMods Jul 29, 2021
b72cc1f
Make error comment match helper function name
MadLittleMods Jul 29, 2021
6bc06f7
Add test for private room backfilling
MadLittleMods Aug 4, 2021
3b2358f
Simplify batchSendHistoricalMessages function signature by using sort…
MadLittleMods Aug 4, 2021
637ac8f
Remove test skips now that it's supported in Synapse
MadLittleMods Aug 10, 2021
b06fc95
Verify we only return state events that we pass in
MadLittleMods Aug 10, 2021
0a215fe
Add tests for MSC2716 being backwards compatible with existing room v…
MadLittleMods Aug 11, 2021
a958b34
Add helper decorations
MadLittleMods Aug 18, 2021
09b4a4b
Add tests to verify ?chunk_id actually corresponds to an insertion ev…
MadLittleMods Sep 7, 2021
ebe141d
Update tests to accomodate /batch_send returning separate meta event …
MadLittleMods Sep 7, 2021
858aef6
More idiomatic Go from review
MadLittleMods Sep 8, 2021
de5d68d
Merge branch 'madlittlemods/msc2716-federation-changes' into madlittl…
MadLittleMods Sep 8, 2021
1de9618
Use txn helper for other txns
MadLittleMods Sep 8, 2021
5c642cf
Merge branch 'master' into madlittlemods/msc2716-room-creator-existin…
MadLittleMods Sep 8, 2021
74b6399
Merge branch 'madlittlemods/msc2716-room-creator-existing-room-versio…
MadLittleMods Sep 10, 2021
dee7eec
Merge branch 'master' into madlittlemods/msc2716-verify-params
MadLittleMods Sep 10, 2021
468b29e
Merge branch 'madlittlemods/msc2716-verify-params' into madlittlemods…
MadLittleMods Sep 10, 2021
2b3535d
Better assertion comments to explain why 2
MadLittleMods Sep 10, 2021
859aa79
Remove useless getter functions
MadLittleMods Sep 10, 2021
98e392c
Rename MSC2716 things from chunk to batch to match `/batch_send` endp…
MadLittleMods Sep 17, 2021
e0997a7
Merge branch 'master' into madlittlemods/split-batch-send-response-fi…
MadLittleMods Sep 21, 2021
cccc304
Merge branch 'madlittlemods/split-batch-send-response-fields' into ma…
MadLittleMods Sep 21, 2021
db25f9f
Merge branch 'master' into madlittlemods/2716-chunk-to-batch-rename
MadLittleMods Sep 21, 2021
46beb9b
Update query parameter to comply with rename
MadLittleMods Sep 21, 2021
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
78 changes: 39 additions & 39 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ const timeBetweenMessages = time.Millisecond

var (
insertionEventType = "org.matrix.msc2716.insertion"
chunkEventType = "org.matrix.msc2716.chunk"
batchEventType = "org.matrix.msc2716.batch"
markerEventType = "org.matrix.msc2716.marker"

historicalContentField = "org.matrix.msc2716.historical"
nextChunkIDContentField = "org.matrix.msc2716.next_chunk_id"
nextBatchIDContentField = "org.matrix.msc2716.next_batch_id"
markerInsertionContentField = "org.matrix.msc2716.marker.insertion"
)

var createPublicRoomOpts = map[string]interface{}{
"preset": "public_chat",
"name": "the hangout spot",
"room_version": "org.matrix.msc2716",
"room_version": "org.matrix.msc2716v3",
}

var createPrivateRoomOpts = map[string]interface{}{
"preset": "private_chat",
"name": "the hangout spot",
"room_version": "org.matrix.msc2716",
"room_version": "org.matrix.msc2716v3",
}

func TestBackfillingHistory(t *testing.T) {
Expand All @@ -82,9 +82,9 @@ func TestBackfillingHistory(t *testing.T) {
t.Run("parallel", func(t *testing.T) {
// Test that the message events we insert between A and B come back in the correct order from /messages
//
// Final timeline output: ( [n] = historical chunk )
// (oldest) A, B, [insertion, c, d, e, chunk] [insertion, f, g, h, chunk, insertion], I, J (newest)
// historical chunk 1 historical chunk 0
// Final timeline output: ( [n] = historical batch )
// (oldest) A, B, [insertion, c, d, e, batch] [insertion, f, g, h, batch, insertion], I, J (newest)
// historical batch 1 historical batch 0
t.Run("Backfilled historical events resolve with proper state in correct order", func(t *testing.T) {
t.Parallel()

Expand All @@ -111,7 +111,7 @@ func TestBackfillingHistory(t *testing.T) {
// inserted history later.
eventIDsAfter := createMessagesInRoom(t, alice, roomID, 2)

// Insert the most recent chunk of backfilled history
// Insert the most recent batch of backfilled history
insertTime0 := timeAfterEventBefore.Add(timeBetweenMessages * 3)
batchSendRes := batchSendHistoricalMessages(
t,
Expand All @@ -127,19 +127,19 @@ func TestBackfillingHistory(t *testing.T) {
batchSendResBody0 := client.ParseJSON(t, batchSendRes)
insertionEventID0 := client.GetJSONFieldStr(t, batchSendResBody0, "insertion_event_id")
historicalEventIDs0 := client.GetJSONFieldStringArray(t, batchSendResBody0, "event_ids")
chunkEventID0 := client.GetJSONFieldStr(t, batchSendResBody0, "chunk_event_id")
batchEventID0 := client.GetJSONFieldStr(t, batchSendResBody0, "batch_event_id")
baseInsertionEventID0 := client.GetJSONFieldStr(t, batchSendResBody0, "base_insertion_event_id")
nextChunkID0 := client.GetJSONFieldStr(t, batchSendResBody0, "next_chunk_id")
nextBatchID0 := client.GetJSONFieldStr(t, batchSendResBody0, "next_batch_id")

// Insert another older chunk of backfilled history from the same user.
// Make sure the meta data and joins still work on the subsequent chunk
// Insert another older batch of backfilled history from the same user.
// Make sure the meta data and joins still work on the subsequent batch
insertTime1 := timeAfterEventBefore
batchSendRes1 := batchSendHistoricalMessages(
t,
as,
roomID,
eventIdBefore,
nextChunkID0,
nextBatchID0,
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, insertTime1),
createMessageEventsForBackfillRequest([]string{virtualUserID}, insertTime1, 3),
// Status
Expand All @@ -148,23 +148,23 @@ func TestBackfillingHistory(t *testing.T) {
batchSendResBody1 := client.ParseJSON(t, batchSendRes1)
insertionEventID1 := client.GetJSONFieldStr(t, batchSendResBody1, "insertion_event_id")
historicalEventIDs1 := client.GetJSONFieldStringArray(t, batchSendResBody1, "event_ids")
chunkEventID1 := client.GetJSONFieldStr(t, batchSendResBody1, "chunk_event_id")
batchEventID1 := client.GetJSONFieldStr(t, batchSendResBody1, "batch_event_id")

var expectedEventIDOrder []string
expectedEventIDOrder = append(expectedEventIDOrder, eventIDsBefore...)
expectedEventIDOrder = append(expectedEventIDOrder, insertionEventID1)
expectedEventIDOrder = append(expectedEventIDOrder, historicalEventIDs1...)
expectedEventIDOrder = append(expectedEventIDOrder, chunkEventID1)
expectedEventIDOrder = append(expectedEventIDOrder, batchEventID1)
expectedEventIDOrder = append(expectedEventIDOrder, insertionEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, historicalEventIDs0...)
expectedEventIDOrder = append(expectedEventIDOrder, chunkEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, batchEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, baseInsertionEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, eventIDsAfter...)
// Order events from newest to oldest
expectedEventIDOrder = reversed(expectedEventIDOrder)

// (oldest) A, B, [insertion, c, d, e, chunk] [insertion, f, g, h, chunk, insertion], I, J (newest)
// historical chunk 1 historical chunk 0
// (oldest) A, B, [insertion, c, d, e, batch] [insertion, f, g, h, batch, insertion], I, J (newest)
// historical batch 1 historical batch 0
if len(expectedEventIDOrder) != 15 {
t.Fatalf("Expected eventID list should be length 15 but saw %d: %s", len(expectedEventIDOrder), expectedEventIDOrder)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestBackfillingHistory(t *testing.T) {
}
})

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

roomID := as.CreateRoom(t, createPublicRoomOpts)
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestBackfillingHistory(t *testing.T) {
)
})

t.Run("Unrecognised chunk_id will throw an error", func(t *testing.T) {
t.Run("Unrecognised batch_id will throw an error", func(t *testing.T) {
t.Parallel()

roomID := as.CreateRoom(t, createPublicRoomOpts)
Expand All @@ -370,7 +370,7 @@ func TestBackfillingHistory(t *testing.T) {
as,
roomID,
eventIdBefore,
"XXX_DOES_NOT_EXIST_CHUNK_ID",
"XXX_DOES_NOT_EXIST_BATCH_ID",
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore),
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, 1),
// Status
Expand Down Expand Up @@ -402,9 +402,9 @@ func TestBackfillingHistory(t *testing.T) {
)
})

t.Run("TODO: Trying to send insertion event with same `next_chunk_id` will reject", func(t *testing.T) {
t.Run("TODO: Trying to send insertion event with same `next_batch_id` will reject", func(t *testing.T) {
t.Skip("Skipping until implemented")
// (room_id, next_chunk_id) should be unique
// (room_id, next_batch_id) should be unique
})

t.Run("Should be able to backfill into private room", func(t *testing.T) {
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestBackfillingHistory(t *testing.T) {
// TODO: Try adding avatar and displayName and see if historical messages get this info
})

t.Run("TODO: What happens when you point multiple chunks at the same insertion event?", func(t *testing.T) {
t.Run("TODO: What happens when you point multiple batches at the same insertion event?", func(t *testing.T) {
t.Skip("Skipping until implemented")
})

Expand Down Expand Up @@ -525,11 +525,11 @@ func TestBackfillingHistory(t *testing.T) {
timeAfterEventBefore := time.Now()

// Create insertion event in the normal DAG
chunkId := "mynextchunkid123"
batchID := "mynextBatchID123"
insertionEvent := b.Event{
Type: insertionEventType,
Content: map[string]interface{}{
nextChunkIDContentField: chunkId,
nextBatchIDContentField: batchID,
historicalContentField: true,
},
}
Expand All @@ -551,7 +551,7 @@ func TestBackfillingHistory(t *testing.T) {
as,
roomID,
eventIdBefore,
chunkId,
batchID,
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore),
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, 2),
// Status
Expand Down Expand Up @@ -809,7 +809,7 @@ func TestBackfillingHistory(t *testing.T) {
})
})

t.Run("Not allowed to redact MSC2716 insertion, chunk, marker events", func(t *testing.T) {
t.Run("Not allowed to redact MSC2716 insertion, batch, marker events", func(t *testing.T) {
t.Parallel()

roomID := as.CreateRoom(t, createUnsupportedMSC2716RoomOpts)
Expand All @@ -834,14 +834,14 @@ func TestBackfillingHistory(t *testing.T) {
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
insertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "insertion_event_id")
chunkEventID := client.GetJSONFieldStr(t, batchSendResBody, "chunk_event_id")
batchEventID := client.GetJSONFieldStr(t, batchSendResBody, "batch_event_id")
baseInsertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "base_insertion_event_id")

// Send the marker event
markerEventID := sendMarkerAndEnsureBackfilled(t, as, alice, roomID, baseInsertionEventID)

redactEventID(t, alice, roomID, insertionEventID, 403)
redactEventID(t, alice, roomID, chunkEventID, 403)
redactEventID(t, alice, roomID, batchEventID, 403)
redactEventID(t, alice, roomID, markerEventID, 403)
})
})
Expand Down Expand Up @@ -914,7 +914,7 @@ func fetchUntilMessagesResponseHas(t *testing.T, c *client.CSAPI, roomID string,
func isRelevantEvent(r gjson.Result) bool {
return len(r.Get("content").Get("body").Str) > 0 ||
r.Get("type").Str == insertionEventType ||
r.Get("type").Str == chunkEventType ||
r.Get("type").Str == batchEventType ||
r.Get("type").Str == markerEventType
}

Expand Down Expand Up @@ -1088,7 +1088,7 @@ func createMessageEventsForBackfillRequest(
"origin_server_ts": insertOriginServerTs + (timeBetweenMessagesMS * uint64(i)),
"content": map[string]interface{}{
"msgtype": "m.text",
"body": fmt.Sprintf("Historical %d (chunk=%d)", i, chunkCount),
"body": fmt.Sprintf("Historical %d (batch=%d)", i, batchCount),
historicalContentField: true,
},
}
Expand Down Expand Up @@ -1119,25 +1119,25 @@ func redactEventID(t *testing.T, c *client.CSAPI, roomID, eventID string, expect
}
}

var chunkCount int64 = 0
var batchCount int64 = 0

func batchSendHistoricalMessages(
t *testing.T,
c *client.CSAPI,
roomID string,
insertAfterEventId string,
chunkID string,
batchID string,
stateEventsAtStart []map[string]interface{},
events []map[string]interface{},
expectedStatus int,
) (res *http.Response) {
t.Helper()

query := make(url.Values, 2)
query.Add("prev_event", insertAfterEventId)
// If provided, connect the chunk to the last insertion point
if chunkID != "" {
query.Add("chunk_id", chunkID)
query.Add("prev_event_id", insertAfterEventId)
// If provided, connect the batch to the last insertion point
if batchID != "" {
query.Add("batch_id", batchID)
}

res = c.DoFunc(
Expand All @@ -1156,7 +1156,7 @@ func batchSendHistoricalMessages(
t.Fatalf("msc2716.batchSendHistoricalMessages got %d HTTP status code from batch send response but want %d", res.StatusCode, expectedStatus)
}

chunkCount++
batchCount++

return res
}