-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add more tests for receiving events while resyncing for a partial join #419
Merged
squahtx
merged 22 commits into
main
from
squah/faster_room_joins_calculate_partial_state_flag_for_backfill
Jul 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a07b041
Factor out CreateMessageEvent() function
7b483be
Factor out `testReceiveEventDuringPartialStateJoin()` function
bd2b688
Add `handleGetMissingEventsRequests()` function to respond to `/get_m…
d085f11
Test whether the homeserver thinks it has full state at a received event
2cbeaae
Allow explicitly specified `/state` and `/state_ids` requests to comp…
894d755
Add simple test for receiving an event with a missing prev event
0643979
Add a test for receiving an event with one missing and one known prev…
5e38528
Add a test for receiving an event with a missing prev event, with one…
2979d24
fixup: s/sent/created/
a5b3c71
fixup: define StateIDsResult struct and send /state_id failures down …
8f5b930
fixup: rename new tests to use parents/grandparents terminology
49e35b4
Revert "Allow explicitly specified `/state` and `/state_ids` requests…
1adf5aa
Faster joins tests: make request handlers more specific
richvdh 74dc057
fixup: Add explicit /state_id and /state handlers instead
5a9832f
Log which /state_ids request is being replied to
d437bfb
fixup: explain purpose of deferred channel read
8abc0e8
fixup: link to synapse#13288
8f0b234
Merge remote-tracking branch 'origin/main' into squah/faster_room_joi…
98907c0
fixup: Use WithRetryUntil to retry /event
47ce7ba
Use Context.WithTimeout instead of a SendFederationRequest goroutine
1a0fa9f
Add comment explaining purpose of early /state_ids request
e3d8197
fixup: Remove .vscode/settings.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,66 +143,8 @@ func TestPartialStateJoin(t *testing.T) { | |
|
||
// derek sends an event in the room | ||
event := psjResult.CreateMessageEvent(t, "derek", nil) | ||
psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) | ||
t.Logf("Derek sent event event ID %s", event.EventID()) | ||
|
||
/* TODO: check that a lazy-loading sync can see the event. Currently this doesn't work, because /sync blocks. | ||
* https://github.com/matrix-org/synapse/issues/13146 | ||
alice.MustSyncUntil(t, | ||
client.SyncReq{ | ||
Filter: buildLazyLoadingSyncFilter(nil), | ||
}, | ||
client.SyncTimelineHasEventID(psjResult.ServerRoom.RoomID, event.EventID()), | ||
) | ||
*/ | ||
|
||
// still, Alice should be able to see the event with an /event request. We might have to try it a few times. | ||
start := time.Now() | ||
for { | ||
if time.Since(start) > time.Second { | ||
t.Fatalf("timeout waiting for received event to be visible") | ||
} | ||
res := alice.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", psjResult.ServerRoom.RoomID, "event", event.EventID()}) | ||
eventResBody := client.ParseJSON(t, res) | ||
if res.StatusCode == 200 { | ||
t.Logf("Successfully fetched received event %s", event.EventID()) | ||
break | ||
} | ||
if res.StatusCode == 404 && gjson.GetBytes(eventResBody, "errcode").String() == "M_NOT_FOUND" { | ||
t.Logf("Fetching received event failed with M_NOT_FOUND; will retry") | ||
time.Sleep(100 * time.Millisecond) | ||
continue | ||
} | ||
t.Fatalf("GET /event failed with %d: %s", res.StatusCode, string(eventResBody)) | ||
} | ||
|
||
// allow the partial join to complete | ||
psjResult.FinishStateRequest() | ||
alice.MustSyncUntil(t, | ||
client.SyncReq{}, | ||
client.SyncJoinedTo(alice.UserID, psjResult.ServerRoom.RoomID), | ||
) | ||
|
||
// check the server's idea of the state at the event. We do this by making a `state_ids` request over federation | ||
stateReq := gomatrixserverlib.NewFederationRequest("GET", "hs1", | ||
fmt.Sprintf("/_matrix/federation/v1/state_ids/%s?event_id=%s", | ||
url.PathEscape(psjResult.ServerRoom.RoomID), | ||
url.QueryEscape(event.EventID()), | ||
), | ||
) | ||
var respStateIDs gomatrixserverlib.RespStateIDs | ||
if err := psjResult.Server.SendFederationRequest(deployment, stateReq, &respStateIDs); err != nil { | ||
t.Errorf("/state_ids request returned non-200: %s", err) | ||
return | ||
} | ||
var gotState, expectedState []interface{} | ||
for _, ev := range respStateIDs.StateEventIDs { | ||
gotState = append(gotState, ev) | ||
} | ||
for _, ev := range psjResult.ServerRoom.AllCurrentState() { | ||
expectedState = append(expectedState, ev.EventID()) | ||
} | ||
must.CheckOffAll(t, gotState, expectedState) | ||
testReceiveEventDuringPartialStateJoin(t, deployment, alice, psjResult, event) | ||
}) | ||
|
||
// a request to (client-side) /members?at= should block until the (federation) /state request completes | ||
|
@@ -505,6 +447,74 @@ func TestPartialStateJoin(t *testing.T) { | |
}) | ||
} | ||
|
||
// test reception of an event over federation during a resync | ||
// sends the given event to the homeserver under test, checks that a client can see it and checks | ||
// the state at the event | ||
func testReceiveEventDuringPartialStateJoin( | ||
t *testing.T, deployment *docker.Deployment, alice *client.CSAPI, psjResult partialStateJoinResult, event *gomatrixserverlib.Event, | ||
) { | ||
// send the event to the homeserver | ||
psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) | ||
|
||
/* TODO: check that a lazy-loading sync can see the event. Currently this doesn't work, because /sync blocks. | ||
* https://github.com/matrix-org/synapse/issues/13146 | ||
alice.MustSyncUntil(t, | ||
client.SyncReq{ | ||
Filter: buildLazyLoadingSyncFilter(nil), | ||
}, | ||
client.SyncTimelineHasEventID(psjResult.ServerRoom.RoomID, event.EventID()), | ||
) | ||
*/ | ||
|
||
// still, Alice should be able to see the event with an /event request. We might have to try it a few times. | ||
start := time.Now() | ||
for { | ||
if time.Since(start) > time.Second { | ||
t.Fatalf("timeout waiting for received event to be visible") | ||
} | ||
res := alice.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", psjResult.ServerRoom.RoomID, "event", event.EventID()}) | ||
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. You can now use WithRetryUntil in your res := alice.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", psjResult.ServerRoom.RoomID, "event", event.EventID()},
client.WithRetryUntil(time.Second, func(res *http.Response) bool {
if res.StatusCode == 200 {
return true
}
eventResBody := client.ParseJSON(t, res)
if res.StatusCode == 404 && gjson.GetBytes(eventResBody, "errcode").String() == "M_NOT_FOUND" {
return false
}
t.Fatalf("GET /event failed with %d: %s", res.StatusCode, string(eventResBody))
return false
}) |
||
eventResBody := client.ParseJSON(t, res) | ||
if res.StatusCode == 200 { | ||
t.Logf("Successfully fetched received event %s", event.EventID()) | ||
break | ||
} | ||
if res.StatusCode == 404 && gjson.GetBytes(eventResBody, "errcode").String() == "M_NOT_FOUND" { | ||
t.Logf("Fetching received event failed with M_NOT_FOUND; will retry") | ||
time.Sleep(100 * time.Millisecond) | ||
continue | ||
} | ||
t.Fatalf("GET /event failed with %d: %s", res.StatusCode, string(eventResBody)) | ||
} | ||
|
||
// allow the partial join to complete | ||
psjResult.FinishStateRequest() | ||
alice.MustSyncUntil(t, | ||
client.SyncReq{}, | ||
client.SyncJoinedTo(alice.UserID, psjResult.ServerRoom.RoomID), | ||
) | ||
|
||
// check the server's idea of the state at the event. We do this by making a `state_ids` request over federation | ||
stateReq := gomatrixserverlib.NewFederationRequest("GET", "hs1", | ||
fmt.Sprintf("/_matrix/federation/v1/state_ids/%s?event_id=%s", | ||
url.PathEscape(psjResult.ServerRoom.RoomID), | ||
url.QueryEscape(event.EventID()), | ||
), | ||
) | ||
var respStateIDs gomatrixserverlib.RespStateIDs | ||
if err := psjResult.Server.SendFederationRequest(deployment, stateReq, &respStateIDs); err != nil { | ||
t.Errorf("/state_ids request returned non-200: %s", err) | ||
return | ||
} | ||
var gotState, expectedState []interface{} | ||
for _, ev := range respStateIDs.StateEventIDs { | ||
gotState = append(gotState, ev) | ||
} | ||
for _, ev := range psjResult.ServerRoom.AllCurrentState() { | ||
expectedState = append(expectedState, ev.EventID()) | ||
} | ||
must.CheckOffAll(t, gotState, expectedState) | ||
} | ||
|
||
// buildLazyLoadingSyncFilter constructs a json-marshalled filter suitable the 'Filter' field of a client.SyncReq | ||
func buildLazyLoadingSyncFilter(timelineOptions map[string]interface{}) string { | ||
timelineFilter := map[string]interface{}{ | ||
|
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.
s/sent/created/ here