Skip to content

Commit 44111a2

Browse files
Add some tests for push rule behavior on room upgrade (#819)
In Synapse, this behavior is handled by [`transfer_room_state_on_room_upgrade`](https://github.com/element-hq/synapse/blob/322481cd2d694eb5fe6107f3c0cd8d48252439bc/synapse/handlers/room_member.py#L1344-L1348) -> `copy_user_state_on_room_upgrade` -> [`copy_push_rules_from_room_to_room_for_user`](https://github.com/element-hq/synapse/blob/322481cd2d694eb5fe6107f3c0cd8d48252439bc/synapse/storage/databases/main/push_rule.py#L943-L947). In Dendrite, this behavior is handled by [`handleRoomUpgrade`](https://github.com/element-hq/dendrite/blob/fbbdf84ac62699ee952e091b4a8cc9577bd4f6bb/userapi/consumers/roomserver.go#L209-L227) -> [`copyPushrules`](https://github.com/element-hq/dendrite/blob/fbbdf84ac62699ee952e091b4a8cc9577bd4f6bb/userapi/consumers/roomserver.go#L229-L254). This behavior is not explained in the [Matrix spec](https://spec.matrix.org/v1.16/client-server-api/#server-behaviour-19) but perhaps that just needs a clarification/MSC to document the state of things. Synapse and Dendrite do this for example. --- This is spawning from wanting to see whether I can reproduce an issue I was experiencing during the recent room upgrades to v12. I previously had my notification settings for a room as "Mentions & keywords" in Element Web but then after the upgrade, it was using the "Match default settings" and I was receiving notifications for all new messages. The tests do now reproduce the problem! See element-hq/synapse#19199
1 parent f67a50e commit 44111a2

File tree

2 files changed

+422
-0
lines changed

2 files changed

+422
-0
lines changed

client/client.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,31 @@ func (c *CSAPI) CreateRoom(t ct.TestLike, body map[string]interface{}) *http.Res
174174
return c.Do(t, "POST", []string{"_matrix", "client", "v3", "createRoom"}, WithJSONBody(t, body))
175175
}
176176

177+
// MustUpgradeRoom upgrades a room to the newVersion. Fails the test on error. Returns the new room ID.
178+
func (c *CSAPI) MustUpgradeRoom(t ct.TestLike, roomID string, newVersion string) string {
179+
t.Helper()
180+
res := c.UpgradeRoom(t, roomID, newVersion)
181+
mustRespond2xx(t, res)
182+
resBody := ParseJSON(t, res)
183+
return GetJSONFieldStr(t, resBody, "replacement_room")
184+
}
185+
186+
// UpgradeRoom upgrades a room to the newVersion
187+
func (c *CSAPI) UpgradeRoom(t ct.TestLike, roomID string, newVersion string) *http.Response {
188+
t.Helper()
189+
// Ensure we don't call create a room (upgrade creates a new room) from the same user
190+
// in parallel, else we might try to make 2 rooms in the same millisecond (same
191+
// `origin_server_ts`), causing v12 rooms to get the same room ID thus failing the
192+
// test.
193+
c.createRoomMutex.Lock()
194+
defer c.createRoomMutex.Unlock()
195+
return c.Do(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "upgrade"},
196+
WithJSONBody(t, map[string]string{
197+
"new_version": newVersion,
198+
}),
199+
)
200+
}
201+
177202
// MustJoinRoom joins the room ID or alias given, else fails the test. Returns the room ID.
178203
//
179204
// Args:
@@ -214,6 +239,21 @@ func (c *CSAPI) JoinRoom(t ct.TestLike, roomIDOrAlias string, serverNames []spec
214239
)
215240
}
216241

242+
// MustAwaitPartialStateJoinCompletion waits until the joined room is no longer partial-stated
243+
func (c *CSAPI) MustAwaitPartialStateJoinCompletion(t ct.TestLike, room_id string) {
244+
t.Helper()
245+
246+
// Use a `/members` request to wait for the room to be un-partial stated.
247+
// We avoid using `/sync`, as it only waits (or used to wait) for full state at
248+
// particular events, rather than the whole room.
249+
c.MustDo(
250+
t,
251+
"GET",
252+
[]string{"_matrix", "client", "v3", "rooms", room_id, "members"},
253+
)
254+
t.Logf("%s's partial state join to %s completed.", c.UserID, room_id)
255+
}
256+
217257
// MustLeaveRoom leaves the room ID, else fails the test.
218258
func (c *CSAPI) MustLeaveRoom(t ct.TestLike, roomID string) {
219259
res := c.LeaveRoom(t, roomID)

0 commit comments

Comments
 (0)