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

Update tests to accommodate /batch_send returning separate meta event fields (MSC2716) #204

Merged
merged 24 commits into from
Sep 21, 2021
Merged
Changes from all commits
Commits
Show all changes
24 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
e0997a7
Merge branch 'master' into madlittlemods/split-batch-send-response-fi…
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
97 changes: 47 additions & 50 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,43 +112,53 @@ func TestBackfillingHistory(t *testing.T) {
eventIDsAfter := createMessagesInRoom(t, alice, roomID, 2)

// Insert the most recent chunk of backfilled history
insertTime1 := timeAfterEventBefore.Add(timeBetweenMessages * 3)
insertTime0 := timeAfterEventBefore.Add(timeBetweenMessages * 3)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating from insertTime1 -> insertTime0 to match the chunk explanation below

batchSendRes := batchSendHistoricalMessages(
t,
as,
roomID,
eventIdBefore,
"",
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, insertTime1),
createMessageEventsForBackfillRequest([]string{virtualUserID}, insertTime1, 3),
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, insertTime0),
createMessageEventsForBackfillRequest([]string{virtualUserID}, insertTime0, 3),
// Status
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
nextChunkID := getNextChunkIdFromBatchSendResponseBody(t, batchSendResBody)
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")
baseInsertionEventID0 := client.GetJSONFieldStr(t, batchSendResBody0, "base_insertion_event_id")
nextChunkID0 := client.GetJSONFieldStr(t, batchSendResBody0, "next_chunk_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
insertTime2 := timeAfterEventBefore
batchSendRes2 := batchSendHistoricalMessages(
insertTime1 := timeAfterEventBefore
batchSendRes1 := batchSendHistoricalMessages(
t,
as,
roomID,
eventIdBefore,
nextChunkID,
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, insertTime2),
createMessageEventsForBackfillRequest([]string{virtualUserID}, insertTime2, 3),
nextChunkID0,
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, insertTime1),
createMessageEventsForBackfillRequest([]string{virtualUserID}, insertTime1, 3),
// Status
200,
)
batchSendResBody2 := client.ParseJSON(t, batchSendRes2)
historicalEventIDs2 := getEventsFromBatchSendResponseBody(t, batchSendResBody2)
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")

var expectedEventIDOrder []string
expectedEventIDOrder = append(expectedEventIDOrder, eventIDsBefore...)
expectedEventIDOrder = append(expectedEventIDOrder, historicalEventIDs2...)
expectedEventIDOrder = append(expectedEventIDOrder, historicalEventIDs...)
expectedEventIDOrder = append(expectedEventIDOrder, insertionEventID1)
expectedEventIDOrder = append(expectedEventIDOrder, historicalEventIDs1...)
expectedEventIDOrder = append(expectedEventIDOrder, chunkEventID1)
expectedEventIDOrder = append(expectedEventIDOrder, insertionEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, historicalEventIDs0...)
expectedEventIDOrder = append(expectedEventIDOrder, chunkEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, baseInsertionEventID0)
expectedEventIDOrder = append(expectedEventIDOrder, eventIDsAfter...)
// Order events from newest to oldest
expectedEventIDOrder = reversed(expectedEventIDOrder)
Expand Down Expand Up @@ -228,7 +238,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")

messagesRes := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
"dir": []string{"b"},
Expand Down Expand Up @@ -271,7 +281,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")
backfilledEventId := historicalEventIDs[0]

// This is just a dummy event we search for after the backfilledEventId
Expand Down Expand Up @@ -314,7 +324,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
stateEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "state_events")
stateEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "state_event_ids")

// We only expect 1 state event to be returned because we only passed in 1
// event into `?state_events_at_start`
Expand Down Expand Up @@ -426,7 +436,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")

messagesRes := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
"dir": []string{"b"},
Expand Down Expand Up @@ -476,7 +486,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")

// Join the room from a remote homeserver after the backfilled messages were sent
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})
Expand Down Expand Up @@ -548,7 +558,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")

// Join the room from a remote homeserver after the backfilled messages were sent
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})
Expand Down Expand Up @@ -599,24 +609,24 @@ func TestBackfillingHistory(t *testing.T) {
"limit": []string{"5"},
}))

numMessagesSent := 2
batchSendRes := batchSendHistoricalMessages(
t,
as,
roomID,
eventIdBefore,
"",
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore),
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, 2),
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, numMessagesSent),
// Status
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
baseInsertionEventID := historicalEventIDs[len(historicalEventIDs)-1]
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")
baseInsertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "base_insertion_event_id")

// [1 insertion event + 2 historical events + 1 chunk event + 1 insertion event]
if len(historicalEventIDs) != 5 {
t.Fatalf("Expected eventID list should be length 5 but saw %d: %v", len(historicalEventIDs), historicalEventIDs)
if len(historicalEventIDs) != numMessagesSent {
t.Fatalf("Expected %d event_ids in the response that correspond to the %d events we sent in the request but saw %d: %s", numMessagesSent, numMessagesSent, len(historicalEventIDs), historicalEventIDs)
}

beforeMarkerMessagesRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
Expand Down Expand Up @@ -688,24 +698,24 @@ func TestBackfillingHistory(t *testing.T) {
}))

// Historical messages are inserted where we have already scrolled back to
numMessagesSent := 2
batchSendRes := batchSendHistoricalMessages(
t,
as,
roomID,
eventIdBefore,
"",
createJoinStateEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore),
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, 2),
createMessageEventsForBackfillRequest([]string{virtualUserID}, timeAfterEventBefore, numMessagesSent),
// Status
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
baseInsertionEventID := historicalEventIDs[len(historicalEventIDs)-1]
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")
baseInsertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "base_insertion_event_id")

// [1 insertion event + 2 historical events + 1 chunk event + 1 insertion event]
if len(historicalEventIDs) != 5 {
t.Fatalf("Expected eventID list should be length 5 but saw %d: %s", len(historicalEventIDs), historicalEventIDs)
if len(historicalEventIDs) != numMessagesSent {
t.Fatalf("Expected %d event_ids in the response that correspond to the %d events we sent in the request but saw %d: %s", numMessagesSent, numMessagesSent, len(historicalEventIDs), historicalEventIDs)
}

beforeMarkerMessagesRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
Expand Down Expand Up @@ -783,7 +793,7 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")

messagesRes := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
"dir": []string{"b"},
Expand Down Expand Up @@ -823,10 +833,9 @@ func TestBackfillingHistory(t *testing.T) {
200,
)
batchSendResBody := client.ParseJSON(t, batchSendRes)
historicalEventIDs := getEventsFromBatchSendResponseBody(t, batchSendResBody)
insertionEventID := historicalEventIDs[0]
chunkEventID := historicalEventIDs[2]
baseInsertionEventID := historicalEventIDs[3]
insertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "insertion_event_id")
chunkEventID := client.GetJSONFieldStr(t, batchSendResBody, "chunk_event_id")
baseInsertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "base_insertion_event_id")

// Send the marker event
markerEventID := sendMarkerAndEnsureBackfilled(t, as, alice, roomID, baseInsertionEventID)
Expand Down Expand Up @@ -1151,15 +1160,3 @@ func batchSendHistoricalMessages(

return res
}

func getEventsFromBatchSendResponseBody(t *testing.T, body []byte) (eventIDs []string) {
eventIDs = client.GetJSONFieldStringArray(t, body, "events")

return eventIDs
}

func getNextChunkIdFromBatchSendResponseBody(t *testing.T, body []byte) (nextChunkID string) {
nextChunkID = client.GetJSONFieldStr(t, body, "next_chunk_id")

return nextChunkID
}