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

Faster room joins: Add abandoned join tests for device list tracking #476

Merged
81 changes: 79 additions & 2 deletions tests/federation_room_join_partial_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,8 @@ func TestPartialStateJoin(t *testing.T) {
server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil)
awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken)

// @elsie's device list ought to be cached.
// @elsie's device list ought to be cached after the first request.
// Try to bring their device list into the homeserver's cache, then test whether it really was cached.
syncToken = mustSyncUntilDeviceListsHas(t, alice, syncToken, "changed", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
mustQueryKeysWithoutFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
Expand Down Expand Up @@ -2390,7 +2391,8 @@ func TestPartialStateJoin(t *testing.T) {
server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil)
awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken)

// @elsie's device list ought to be cached.
// @elsie's device list ought to be cached after the first request.
// Try to bring their device list into the homeserver's cache, then test whether it really was cached.
syncToken = mustSyncUntilDeviceListsHas(t, alice, syncToken, "changed", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
mustQueryKeysWithoutFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
Expand All @@ -2405,6 +2407,81 @@ func TestPartialStateJoin(t *testing.T) {
mustSyncUntilDeviceListsHas(t, alice, syncToken, "left", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
})

// test that device lists stop being tracked when leaving a partial state room before the
// partial state join completes.
t.Run("Device list no longer tracked when leaving partial state room", func(t *testing.T) {
// Skipped until https://github.com/matrix-org/synapse/issues/12802 has been addressed.
t.Skip("Cannot yet leave a room during resync")
richvdh marked this conversation as resolved.
Show resolved Hide resolved

alice, server, userDevicesChannel, room, _, cleanup := setupDeviceListCachingTest(t, deployment, "t34alice")
defer cleanup()

// The room starts with @charlie and @derek in it.

// @t34alice:hs1 joins the room.
psjResult := beginPartialStateJoin(t, server, room, alice)
defer psjResult.Destroy()

syncToken := getSyncToken(t, alice)

// @elsie joins the room.
joinEvent := createJoinEvent(t, server, room, server.UserID("elsie"))
room.AddEvent(joinEvent)
server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil)
awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken)

// @elsie's device list ought to be cached after the first request.
// Try to bring their device list into the homeserver's cache, then test whether it really was cached.
syncToken = mustSyncUntilDeviceListsHas(t, alice, syncToken, "changed", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
richvdh marked this conversation as resolved.
Show resolved Hide resolved
mustQueryKeysWithoutFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))

// alice aborts her join before the resync completes
alice.LeaveRoom(t, room.RoomID)

// @elsie's device list ought to no longer be cached.
mustSyncUntilDeviceListsHas(t, alice, syncToken, "left", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
})

// test that device lists stop being tracked when leaving a partial state room due to
// failure to complete the partial state join.
t.Run("Device list no longer tracked when failing to complete partial state join", func(t *testing.T) {
// Skipped until https://github.com/matrix-org/synapse/issues/13000 has been addressed.
t.Skip("Cannot yet abort a partial state join")

alice, server, userDevicesChannel, room, _, cleanup := setupDeviceListCachingTest(t, deployment, "t35alice")
defer cleanup()

// The room starts with @charlie and @derek in it.

// @t35alice:hs1 joins the room.
psjResult := beginPartialStateJoin(t, server, room, alice)
defer psjResult.Destroy()

syncToken := getSyncToken(t, alice)

// @elsie joins the room.
joinEvent := createJoinEvent(t, server, room, server.UserID("elsie"))
room.AddEvent(joinEvent)
server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil)
awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), "")

// @elsie's device list ought to be cached after the first request.
// Try to bring their device list into the homeserver's cache, then test whether it really was cached.
syncToken = mustSyncUntilDeviceListsHas(t, alice, syncToken, "changed", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
mustQueryKeysWithoutFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))

t.Fatalf("TODO: fail the partial state join")
psjResult.FinishStateRequest()
awaitPartialStateJoinCompletion(t, room, alice)

// @elsie's device list ought to no longer be cached.
mustSyncUntilDeviceListsHas(t, alice, syncToken, "left", server.UserID("elsie"))
mustQueryKeysWithFederationRequest(t, alice, userDevicesChannel, server.UserID("elsie"))
})
})
}

Expand Down