Skip to content
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
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
Jul 21, 2022
7b483be
Factor out `testReceiveEventDuringPartialStateJoin()` function
Jul 21, 2022
bd2b688
Add `handleGetMissingEventsRequests()` function to respond to `/get_m…
Jul 21, 2022
d085f11
Test whether the homeserver thinks it has full state at a received event
Jul 21, 2022
2cbeaae
Allow explicitly specified `/state` and `/state_ids` requests to comp…
Jul 21, 2022
894d755
Add simple test for receiving an event with a missing prev event
Jul 21, 2022
0643979
Add a test for receiving an event with one missing and one known prev…
Jul 21, 2022
5e38528
Add a test for receiving an event with a missing prev event, with one…
Jul 21, 2022
2979d24
fixup: s/sent/created/
Jul 22, 2022
a5b3c71
fixup: define StateIDsResult struct and send /state_id failures down …
Jul 22, 2022
8f5b930
fixup: rename new tests to use parents/grandparents terminology
Jul 22, 2022
49e35b4
Revert "Allow explicitly specified `/state` and `/state_ids` requests…
Jul 22, 2022
1adf5aa
Faster joins tests: make request handlers more specific
richvdh Jul 21, 2022
74dc057
fixup: Add explicit /state_id and /state handlers instead
Jul 22, 2022
5a9832f
Log which /state_ids request is being replied to
Jul 22, 2022
d437bfb
fixup: explain purpose of deferred channel read
Jul 22, 2022
8abc0e8
fixup: link to synapse#13288
Jul 22, 2022
8f0b234
Merge remote-tracking branch 'origin/main' into squah/faster_room_joi…
Jul 22, 2022
98907c0
fixup: Use WithRetryUntil to retry /event
Jul 25, 2022
47ce7ba
Use Context.WithTimeout instead of a SendFederationRequest goroutine
Jul 25, 2022
1a0fa9f
Add comment explaining purpose of early /state_ids request
Jul 25, 2022
e3d8197
fixup: Remove .vscode/settings.json
Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions tests/federation_room_join_partial_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ type partialStateJoinResult struct {
ServerRoom *federation.ServerRoom
fedStateIdsRequestReceivedWaiter *Waiter
fedStateIdsSendResponseWaiter *Waiter
// the set of events for which we will not block `/state` or `/state_ids` requests.
fedStateIdsAllowedEvents map[string]bool
}

// beginPartialStateJoin spins up a room on a complement server,
Expand Down Expand Up @@ -627,6 +629,7 @@ func beginPartialStateJoin(t *testing.T, deployment *docker.Deployment, joiningU
// some things for orchestration
result.fedStateIdsRequestReceivedWaiter = NewWaiter()
result.fedStateIdsSendResponseWaiter = NewWaiter()
result.fedStateIdsAllowedEvents = make(map[string]bool)

// create the room on the complement server, with charlie and derek as members
roomVer := joiningUser.GetDefaultRoomVersion(t)
Expand All @@ -642,10 +645,17 @@ func beginPartialStateJoin(t *testing.T, deployment *docker.Deployment, joiningU

// register a handler for /state_ids requests, which finishes fedStateIdsRequestReceivedWaiter, then
// waits for fedStateIdsSendResponseWaiter and sends a reply
handleStateIdsRequests(t, result.Server, result.ServerRoom, result.fedStateIdsRequestReceivedWaiter, result.fedStateIdsSendResponseWaiter)
handleStateIdsRequests(
t,
result.Server,
result.ServerRoom,
result.fedStateIdsRequestReceivedWaiter,
result.fedStateIdsSendResponseWaiter,
result.fedStateIdsAllowedEvents,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be easier to flip this around, and have handleStateIdsRequests only match /state_ids requests for the last event before the join event? That's what I did in #418, in 687ad36.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks a lot cleaner. I've borrowed that commit and it works great. Do we want to split that change into a separate PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'll do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

// a handler for /state requests, which sends a sensible response
handleStateRequests(t, result.Server, result.ServerRoom, nil, nil)
handleStateRequests(t, result.Server, result.ServerRoom, nil, nil, nil)

// have joiningUser join the room by room ID.
joiningUser.JoinRoom(t, result.ServerRoom.RoomID, []string{result.Server.ServerName()})
Expand Down Expand Up @@ -693,6 +703,12 @@ func (psj *partialStateJoinResult) CreateMessageEvent(t *testing.T, senderLocalp
return event
}

// allow a /state_ids request for a given event to complete before FinishStateRequest has been called.
// only applies to new incoming requests, and not any currently blocked ones.
func (psj *partialStateJoinResult) AllowStateRequestForEvent(eventID string) {
psj.fedStateIdsAllowedEvents[eventID] = true
}

// wait for a /state_ids request for the test room to arrive
func (psj *partialStateJoinResult) AwaitStateIdsRequest(t *testing.T) {
psj.fedStateIdsRequestReceivedWaiter.Waitf(t, 5*time.Second, "Waiting for /state_ids request")
Expand All @@ -709,7 +725,7 @@ func (psj *partialStateJoinResult) FinishStateRequest() {
// if sendResponseWaiter is not nil, we will Wait() for it to finish before sending the response.
func handleStateIdsRequests(
t *testing.T, srv *federation.Server, serverRoom *federation.ServerRoom,
requestReceivedWaiter *Waiter, sendResponseWaiter *Waiter,
requestReceivedWaiter *Waiter, sendResponseWaiter *Waiter, allowedEvents map[string]bool,
) {
srv.Mux().Handle(
fmt.Sprintf("/_matrix/federation/v1/state_ids/%s", serverRoom.RoomID),
Expand All @@ -719,7 +735,8 @@ func handleStateIdsRequests(
if requestReceivedWaiter != nil {
requestReceivedWaiter.Finish()
}
if sendResponseWaiter != nil {
if !allowedEvents[queryParams["event_id"][0]] &&
sendResponseWaiter != nil {
sendResponseWaiter.Waitf(t, 60*time.Second, "Waiting for /state_ids request")
}
t.Logf("Replying to /state_ids request")
Expand All @@ -744,7 +761,7 @@ func handleStateIdsRequests(
// if sendResponseWaiter is not nil, we will Wait() for it to finish before sending the response.
func handleStateRequests(
t *testing.T, srv *federation.Server, serverRoom *federation.ServerRoom,
requestReceivedWaiter *Waiter, sendResponseWaiter *Waiter,
requestReceivedWaiter *Waiter, sendResponseWaiter *Waiter, allowedEvents map[string]bool,
) {
srv.Mux().Handle(
fmt.Sprintf("/_matrix/federation/v1/state/%s", serverRoom.RoomID),
Expand All @@ -754,7 +771,8 @@ func handleStateRequests(
if requestReceivedWaiter != nil {
requestReceivedWaiter.Finish()
}
if sendResponseWaiter != nil {
if !allowedEvents[queryParams["event_id"][0]] &&
sendResponseWaiter != nil {
sendResponseWaiter.Waitf(t, 60*time.Second, "Waiting for /state request")
}
res := gomatrixserverlib.RespState{
Expand Down