-
Notifications
You must be signed in to change notification settings - Fork 62
Add TestFederationStateResolution test
#832
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
base: main
Are you sure you want to change the base?
Add TestFederationStateResolution test
#832
Conversation
| cancel := srv.Listen() | ||
| defer cancel() | ||
|
|
||
| hsName := "hs1" |
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.
I'd be tempted just to inline this.
The placement here makes it bit weird to figure out whether it pertains to the real homeserver from the deployment vs the engineered homeserver from Complement.
| // v v | ||
| // | ||
| // what is the current state here | ||
| func TestFederationStateResolution(t *testing.T) { |
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.
| func TestFederationStateResolution(t *testing.T) { | |
| func TestFederationStateConflictResolution(t *testing.T) { |
| ver := alice.GetDefaultRoomVersion(t) | ||
| serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, bob)) | ||
|
|
||
| getName := func() string { |
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.
Probably better as a func getRoomName(...) helper below without it being nested here
| // Join Charlie - this will be a federated join as the server is not yet in the room | ||
| charlie.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{srv.ServerName()}) | ||
| charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, serverRoom.RoomID)) | ||
| serverRoom.WaiterForMembershipEvent(charlie.UserID).Waitf(t, 5*time.Second, "failed to see alice join complement server") |
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.
| serverRoom.WaiterForMembershipEvent(charlie.UserID).Waitf(t, 5*time.Second, "failed to see alice join complement server") | |
| serverRoom.WaiterForMembershipEvent(charlie.UserID).Waitf(t, 5*time.Second, "failed to see charlie join complement server") |
| serverRoom.MustHaveMembershipForUser(t, alice.UserID, "join") | ||
|
|
||
| // Send updated power levels so alice can set the room name. | ||
| pwlvlEvt := srv.MustCreateEvent(t, serverRoom, federation.Event{ |
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.
| pwlvlEvt := srv.MustCreateEvent(t, serverRoom, federation.Event{ | |
| powerlevelEvent := srv.MustCreateEvent(t, serverRoom, federation.Event{ |
|
|
||
| // Alice now sets the room name, which is allowed. Notably it is this event that will be lost | ||
| // due to the state reset. | ||
| e2 := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{ |
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.
Better name especially since we refer to this name in the error messages
| e2 := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{ | |
| roomNameChangeFromAlice := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{ |
(applies to all of the e2, s2, type stuff)
| Type: "m.room.name", | ||
| StateKey: b.Ptr(""), | ||
| Content: map[string]any{ | ||
| "name": "Bad name", |
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.
| "name": "Bad name", | |
| "name": "another name", |
It's not a bad name so let's not mark it as such. It's "some state that will be rolled back because we will later do xxx"
| // dropped is an unfortunate consequence of the state res v2 algorithm, as described here: | ||
| // https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/state_res_msc/proposals/1442-state-resolution.md#state-resets | ||
| if name := getName(); name == "Bad name" { | ||
| ct.Fatalf(t, "initial name not restored after state resolution, got: %s", name) |
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.
We should also show the expected name
| if name := getName(); name == "Bad name" { | ||
| ct.Fatalf(t, "initial name not restored after state resolution, got: %s", name) | ||
| } else if name == "" { | ||
| t.Log("original name not restored") | ||
| } |
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.
I would expect this check to look more like, if not equal to the name we expect to be rolled back to then error
| return w | ||
| } | ||
|
|
||
| func (r *ServerRoom) WaiterForMembershipEvent(userID string) *helpers.Waiter { |
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.
We could make this a general WaiterForStateEvent thing 🤷
Might make it more appetizing to write engineered tests
While working on babbleserv I threw this test together for some basic state res validation.
Pull Request Checklist
Signed-off-by: Nick @ Beeper (@Fizzadar) <nick@beeper.com)