From 8fc31def5474af53e4a20f9eaca4b542861ce42c Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 6 Jul 2022 14:17:22 -0500 Subject: [PATCH 1/2] Add test to make sure we can backfill from where we find an event --- tests/msc3030_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/msc3030_test.go b/tests/msc3030_test.go index de06d45a..f81c709f 100644 --- a/tests/msc3030_test.go +++ b/tests/msc3030_test.go @@ -16,6 +16,7 @@ import ( "github.com/matrix-org/complement/internal/b" "github.com/matrix-org/complement/internal/client" + "github.com/sirupsen/logrus" "github.com/tidwall/gjson" ) @@ -127,6 +128,22 @@ func TestJumpToDateEndpoint(t *testing.T) { remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) }) + + t.Run("can get pagination token after getting remote event from timestamp to event endpoint", func(t *testing.T) { + t.Parallel() + roomID, _, eventB := createTestRoom(t, alice) + remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) + mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) + + contextRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", eventB.EventID}, client.WithContentType("application/json"), client.WithQueries(url.Values{ + "limit": []string{"0"}, + })) + contextResResBody := client.ParseJSON(t, contextRes) + paginationToken := client.GetJSONFieldStr(t, contextResResBody, "end") + logrus.WithFields(logrus.Fields{ + "paginationToken": paginationToken, + }).Error("asdf") + }) }) }) } From 315e1eddf2a2a888d2123a16129fd384b7c7abd6 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 11 Jul 2022 17:26:49 -0500 Subject: [PATCH 2/2] Actually try to paginate with token --- tests/msc3030_test.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/msc3030_test.go b/tests/msc3030_test.go index 980fe4b5..9d9457fb 100644 --- a/tests/msc3030_test.go +++ b/tests/msc3030_test.go @@ -16,7 +16,8 @@ import ( "github.com/matrix-org/complement/internal/b" "github.com/matrix-org/complement/internal/client" - "github.com/sirupsen/logrus" + "github.com/matrix-org/complement/internal/match" + "github.com/matrix-org/complement/internal/must" "github.com/tidwall/gjson" ) @@ -165,20 +166,34 @@ func TestJumpToDateEndpoint(t *testing.T) { mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, timeBeforeRoomCreation, "b", importedEventID) }) - t.Run("can get pagination token after getting remote event from timestamp to event endpoint", func(t *testing.T) { + t.Run("can paginate after getting remote event from timestamp to event endpoint", func(t *testing.T) { t.Parallel() - roomID, _, eventB := createTestRoom(t, alice) + roomID, eventA, eventB := createTestRoom(t, alice) remoteCharlie.JoinRoom(t, roomID, []string{"hs1"}) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) + // Get a pagination token from eventB contextRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", eventB.EventID}, client.WithContentType("application/json"), client.WithQueries(url.Values{ "limit": []string{"0"}, })) contextResResBody := client.ParseJSON(t, contextRes) paginationToken := client.GetJSONFieldStr(t, contextResResBody, "end") - logrus.WithFields(logrus.Fields{ - "paginationToken": paginationToken, - }).Error("asdf") + + // Paginate backwards from eventB + messagesRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ + "dir": []string{"b"}, + "limit": []string{"100"}, + "from": []string{paginationToken}, + })) + + // Make sure both messages are visible + must.MatchResponse(t, messagesRes, match.HTTPResponse{ + JSON: []match.JSON{ + match.JSONCheckOffAllowUnwanted("chunk", []interface{}{eventA.EventID, eventB.EventID}, func(r gjson.Result) interface{} { + return r.Get("event_id").Str + }, nil), + }, + }) }) }) })