-
Notifications
You must be signed in to change notification settings - Fork 55
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
Use stable MSC3030 /timestamp_to_event
endpoints
#559
Merged
MadLittleMods
merged 6 commits into
main
from
madlittlemods/14390-stable-timestamp-to-event-endpoint
Nov 28, 2022
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11bea9a
Use stable MSC3030 endpoints
MadLittleMods 796eaa9
Better failure when expected event but none returned
MadLittleMods 9b2ba1a
MSC3030 timestamp to event is stable
MadLittleMods 153bf71
Move fetchUntilMessagesResponseHas to file that is always in the buil…
MadLittleMods d2bff39
Move getTxnID over as well
MadLittleMods 69cf9f5
Better wording
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
//go:build msc3030 | ||
// +build msc3030 | ||
//go:build !dendrite_blacklist | ||
// +build !dendrite_blacklist | ||
|
||
// This file contains tests for a jump to date API endpoint, | ||
// currently experimental feature defined by MSC3030, which you can read here: | ||
// https://github.com/matrix-org/matrix-doc/pull/3030 | ||
// This file contains tests for the `/timestamp_to_event` client and federation API | ||
// endpoints (also known as *jump to date*). As defined by MSC3030, which you can read | ||
// here: https://github.com/matrix-org/matrix-doc/pull/3030 | ||
|
||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
package tests | ||
|
||
|
@@ -118,7 +118,7 @@ func TestJumpToDateEndpoint(t *testing.T) { | |
// Make the `/timestamp_to_event` request from Bob's perspective (non room member) | ||
timestamp := makeTimestampFromTime(timeBeforeRoomCreation) | ||
timestampString := strconv.FormatInt(timestamp, 10) | ||
timestampToEventRes := nonMemberUser.DoFunc(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc3030", "rooms", roomID, "timestamp_to_event"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
timestampToEventRes := nonMemberUser.DoFunc(t, "GET", []string{"_matrix", "client", "v1", "rooms", roomID, "timestamp_to_event"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
"ts": []string{timestampString}, | ||
"dir": []string{"f"}, | ||
})) | ||
|
@@ -146,7 +146,7 @@ func TestJumpToDateEndpoint(t *testing.T) { | |
// Make the `/timestamp_to_event` request from Bob's perspective (non room member) | ||
timestamp := makeTimestampFromTime(timeBeforeRoomCreation) | ||
timestampString := strconv.FormatInt(timestamp, 10) | ||
timestampToEventRes := nonMemberUser.DoFunc(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc3030", "rooms", roomID, "timestamp_to_event"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
timestampToEventRes := nonMemberUser.DoFunc(t, "GET", []string{"_matrix", "client", "v1", "rooms", roomID, "timestamp_to_event"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
"ts": []string{timestampString}, | ||
"dir": []string{"f"}, | ||
})) | ||
|
@@ -300,19 +300,20 @@ func mustCheckEventisReturnedForTime(t *testing.T, c *client.CSAPI, roomID strin | |
|
||
givenTimestamp := makeTimestampFromTime(givenTime) | ||
timestampString := strconv.FormatInt(givenTimestamp, 10) | ||
timestampToEventRes := c.DoFunc(t, "GET", []string{"_matrix", "client", "unstable", "org.matrix.msc3030", "rooms", roomID, "timestamp_to_event"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
timestampToEventRes := c.DoFunc(t, "GET", []string{"_matrix", "client", "v1", "rooms", roomID, "timestamp_to_event"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
"ts": []string{timestampString}, | ||
"dir": []string{direction}, | ||
})) | ||
timestampToEventResBody := client.ParseJSON(t, timestampToEventRes) | ||
|
||
// Only allow a 200 response meaning we found an event or a 404 meaning we didn't. | ||
// Other status codes will throw and assumed to be application errors. | ||
// Only allow a 200 response meaning we found an event or when no `expectedEventId`, a | ||
// 404 meaning we didn't find anything. Other status codes will throw and assumed to | ||
// be application errors. | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
actualEventId := "" | ||
if timestampToEventRes.StatusCode == 200 { | ||
actualEventId = client.GetJSONFieldStr(t, timestampToEventResBody, "event_id") | ||
} else if timestampToEventRes.StatusCode != 404 { | ||
t.Fatalf("mustCheckEventisReturnedForTime: /timestamp_to_event request failed with status=%d", timestampToEventRes.StatusCode) | ||
} else if timestampToEventRes.StatusCode != 404 || (timestampToEventRes.StatusCode == 404 && expectedEventId != "") { | ||
t.Fatalf("mustCheckEventisReturnedForTime: /timestamp_to_event request failed with status=%d body=%s", timestampToEventRes.StatusCode, string(timestampToEventResBody)) | ||
Comment on lines
+325
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a small fix to make easier to debug when the endpoint fails. We now also throw when the endpoint throws a 404 but we were expecting an event. |
||
} | ||
|
||
if actualEventId != expectedEventId { | ||
|
@@ -327,6 +328,42 @@ func mustCheckEventisReturnedForTime(t *testing.T, c *client.CSAPI, roomID strin | |
} | ||
} | ||
|
||
func fetchUntilMessagesResponseHas(t *testing.T, c *client.CSAPI, roomID string, check func(gjson.Result) bool) { | ||
t.Helper() | ||
start := time.Now() | ||
checkCounter := 0 | ||
for { | ||
if time.Since(start) > c.SyncUntilTimeout { | ||
t.Fatalf("fetchUntilMessagesResponseHas timed out. Called check function %d times", checkCounter) | ||
} | ||
|
||
messagesRes := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "v3", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ | ||
"dir": []string{"b"}, | ||
"limit": []string{"100"}, | ||
})) | ||
messsageResBody := client.ParseJSON(t, messagesRes) | ||
wantKey := "chunk" | ||
keyRes := gjson.GetBytes(messsageResBody, wantKey) | ||
if !keyRes.Exists() { | ||
t.Fatalf("missing key '%s'", wantKey) | ||
} | ||
if !keyRes.IsArray() { | ||
t.Fatalf("key '%s' is not an array (was %s)", wantKey, keyRes.Type) | ||
} | ||
|
||
events := keyRes.Array() | ||
for _, ev := range events { | ||
if check(ev) { | ||
return | ||
} | ||
} | ||
|
||
checkCounter++ | ||
// Add a slight delay so we don't hammmer the messages endpoint | ||
time.Sleep(500 * time.Millisecond) | ||
} | ||
} | ||
|
||
func getDebugMessageListFromMessagesResponse(t *testing.T, c *client.CSAPI, roomID string, expectedEventId string, actualEventId string, givenTimestamp int64) string { | ||
t.Helper() | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this to
tests/room_timestamp_to_event_test.go
because we can't reference it from themsc2716
build tag when it's not included.We don't build with
msc2716
in the workers Complement environment (related matrix-org/synapse#14074). So now we can instead referencefetchUntilMessagesResponseHas
from the file that isn't put behind a build tag.