Skip to content

Commit 3ac5a05

Browse files
committed
Test can be made generic between these two cases
1 parent 77559bf commit 3ac5a05

File tree

1 file changed

+26
-86
lines changed

1 file changed

+26
-86
lines changed

tests/msc2716_test.go

Lines changed: 26 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -919,96 +919,18 @@ func TestImportHistoricalMessages(t *testing.T) {
919919
})
920920
})
921921

922-
t.Run("Historical messages show up for remote federated homeserver even when the homeserver is missing the part of the timeline where the marker was sent and it paginates before it occured", func(t *testing.T) {
923-
t.Parallel()
924-
925-
roomID := as.CreateRoom(t, createPublicRoomOpts)
926-
alice.JoinRoom(t, roomID, nil)
927-
928-
eventIDsBefore := createMessagesInRoom(t, alice, roomID, 1, "eventIDsBefore")
929-
eventIdBefore := eventIDsBefore[0]
930-
timeAfterEventBefore := time.Now()
931-
932-
eventIDsAfter := createMessagesInRoom(t, alice, roomID, 3, "eventIDsAfter")
933-
eventIDAfter := eventIDsAfter[0]
934-
935-
// Join the room from a remote homeserver before the historical messages were sent
936-
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})
937-
938-
// Make sure all of the events have been backfilled for the remote user
939-
// before we leave the room
940-
fetchUntilMessagesResponseHas(t, remoteCharlie, roomID, func(ev gjson.Result) bool {
941-
if ev.Get("event_id").Str == eventIdBefore {
942-
return true
943-
}
944-
945-
return false
946-
})
947-
948-
// Leave before the historical messages are imported
949-
remoteCharlie.LeaveRoom(t, roomID)
950-
951-
batchSendRes := batchSendHistoricalMessages(
952-
t,
953-
as,
954-
roomID,
955-
eventIdBefore,
956-
"",
957-
createJoinStateEventsForBatchSendRequest([]string{virtualUserID}, timeAfterEventBefore),
958-
createMessageEventsForBatchSendRequest([]string{virtualUserID}, timeAfterEventBefore, 2),
959-
// Status
960-
200,
961-
)
962-
batchSendResBody := client.ParseJSON(t, batchSendRes)
963-
historicalEventIDs := client.GetJSONFieldStringArray(t, batchSendResBody, "event_ids")
964-
baseInsertionEventID := client.GetJSONFieldStr(t, batchSendResBody, "base_insertion_event_id")
965-
966-
// Send the marker event which lets remote homeservers know there are
967-
// some historical messages back at the given insertion event. We
968-
// purposely use the local user Alice here as remoteCharlie isn't even
969-
// in the room at this point in time and even if they were, the purpose
970-
// of this test is to make sure the remote-join will pick up the state,
971-
// not our backfill here.
972-
sendMarkerAndEnsureBackfilled(t, as, alice, roomID, baseInsertionEventID)
973-
974-
// Add some events after the marker so that remoteCharlie doesn't see the marker
975-
createMessagesInRoom(t, alice, roomID, 3, "eventIDFiller")
976-
977-
// Join the room from a remote homeserver after the historical messages were sent
978-
remoteCharlie.JoinRoom(t, roomID, []string{"hs1"})
979-
980-
// From the remote user, make a /context request for eventIDAfter to get
981-
// pagination token before the marker event
982-
contextRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", eventIDAfter}, client.WithContentType("application/json"), client.WithQueries(url.Values{
983-
"limit": []string{"0"},
984-
}))
985-
contextResResBody := client.ParseJSON(t, contextRes)
986-
paginationTokenBeforeMarker := client.GetJSONFieldStr(t, contextResResBody, "end")
987-
988-
// Start the /messages request from that pagination token which
989-
// jumps/skips over the marker event in the timeline. This is the key
990-
// part of the test. We want to make sure that new marker state can be
991-
// injested and processed to reveal the imported history after a
992-
// remote-join without paginating and backfilling over the spot in the
993-
// timeline with the marker event.
994-
//
995-
// We don't want to use `validateBatchSendRes(t, remoteCharlie, roomID,
996-
// batchSendRes, false)` here because it tests against the full message
997-
// response and we need to skip past the marker in the timeline.
998-
paginateUntilMessageCheckOff(t, remoteCharlie, roomID, paginationTokenBeforeMarker, historicalEventIDs, []string{})
999-
})
1000-
1001-
t.Run("Historical messages show up for remote federated homeserver even when the homeserver is missing the part of the timeline where multiple marker events were sent and it paginates before they occured", func(t *testing.T) {
1002-
t.Parallel()
922+
// We're testing to make sure historical messages show up for a remote
923+
// federated homeserver even when the homeserver is missing the part of
924+
// the timeline where the marker events were sent and it paginates before
925+
// they occured to see if the history is available. Making sure the
926+
// homeserver processes all of the markers from the current state instead
927+
// of just when it sees them in the timeline.
928+
testHistoricalMessagesAppearForRemoteHomeserverWhenMissingPartOfTimelineWithMarker := func(t *testing.T, numBatches int) {
929+
t.Helper()
1003930

1004931
roomID := as.CreateRoom(t, createPublicRoomOpts)
1005932
alice.JoinRoom(t, roomID, nil)
1006933

1007-
// Anything above 1 here should be sufficient to test whether we can
1008-
// follow the state and previous state all the way up to injest all of
1009-
// the marker events along the way
1010-
numBatches := 2
1011-
1012934
eventIDsBefore := createMessagesInRoom(t, alice, roomID, numBatches, "eventIDsBefore")
1013935
timeAfterEventBefore := time.Now()
1014936

@@ -1086,6 +1008,24 @@ func TestImportHistoricalMessages(t *testing.T) {
10861008
// batchSendRes, false)` here because it tests against the full message
10871009
// response and we need to skip past the marker in the timeline.
10881010
paginateUntilMessageCheckOff(t, remoteCharlie, roomID, paginationTokenBeforeMarker, expectedEventIDs, []string{})
1011+
}
1012+
1013+
t.Run("Historical messages show up for remote federated homeserver even when the homeserver is missing the part of the timeline where the marker was sent and it paginates before it occured", func(t *testing.T) {
1014+
t.Parallel()
1015+
1016+
testHistoricalMessagesAppearForRemoteHomeserverWhenMissingPartOfTimelineWithMarker(t, 1)
1017+
})
1018+
1019+
t.Run("Historical messages show up for remote federated homeserver even when the homeserver is missing the part of the timeline where multiple marker events were sent and it paginates before they occured", func(t *testing.T) {
1020+
t.Parallel()
1021+
1022+
testHistoricalMessagesAppearForRemoteHomeserverWhenMissingPartOfTimelineWithMarker(
1023+
t,
1024+
// Anything above 1 here should be sufficient to test whether we can
1025+
// follow the state and previous state all the way up to injest all of
1026+
// the marker events along the way
1027+
2,
1028+
)
10891029
})
10901030
})
10911031

0 commit comments

Comments
 (0)