Skip to content

Commit 218bb90

Browse files
TestJumpToDateEndpoint: Clarify why we use /context end for paginating backwards despite the spec saying "A token that can be used to paginate forwards with." (#852)
Relevant spec: https://spec.matrix.org/v1.17/client-server-api/#get_matrixclientv3roomsroomidcontexteventid There is no functional change to these tests. This is spawning from [using `/context` in another Complement test](element-hq/synapse#19611) and noticing this oddity.
1 parent 9a95290 commit 218bb90

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

tests/room_timestamp_to_event_test.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,20 @@ func TestJumpToDateEndpoint(t *testing.T) {
213213
mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID)
214214

215215
// Get a pagination token from eventB
216-
contextRes := remoteCharlie.MustDo(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", eventB.EventID}, client.WithContentType("application/json"), client.WithQueries(url.Values{
217-
"limit": []string{"0"},
218-
}))
216+
contextRes := remoteCharlie.MustDo(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "context", eventB.EventID},
217+
client.WithContentType("application/json"), client.WithQueries(url.Values{
218+
"limit": []string{"0"},
219+
}),
220+
)
219221
contextResResBody := client.ParseJSON(t, contextRes)
222+
// Remember: Tokens are positions between events. Normally, you would use the
223+
// `start` token to paginate backwards with but for the sake of the test we want
224+
// to paginate `/messages` and want see both A and B in the response; so we use
225+
// the `end` token. The `end` token comes after B.
226+
//
227+
// start end
228+
// | |
229+
// [A] <-- ▼ [B] ▼ <--- [remoteCharlie join]
220230
paginationToken := client.GetJSONFieldStr(t, contextResResBody, "end")
221231

222232
// Hit `/messages` until `eventA` has been backfilled and replicated across
@@ -226,12 +236,15 @@ func TestJumpToDateEndpoint(t *testing.T) {
226236
return ev.Get("event_id").Str == eventA.EventID
227237
})
228238

229-
// Paginate backwards from eventB
230-
messagesRes := remoteCharlie.MustDo(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
231-
"dir": []string{"b"},
232-
"limit": []string{"100"},
233-
"from": []string{paginationToken},
234-
}))
239+
// Paginate backwards from the point after eventB
240+
messagesRes := remoteCharlie.MustDo(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"},
241+
client.WithContentType("application/json"),
242+
client.WithQueries(url.Values{
243+
"dir": []string{"b"},
244+
"limit": []string{"100"},
245+
"from": []string{paginationToken},
246+
}),
247+
)
235248

236249
// Make sure both messages are visible
237250
must.MatchResponse(t, messagesRes, match.HTTPResponse{

0 commit comments

Comments
 (0)