-
Notifications
You must be signed in to change notification settings - Fork 60
Add deployment.GetFullyQualifiedHomeserverName(t, hsName)
to support custom Deployment
#780
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
Changes from all commits
1faf2aa
e5ff236
48b4af2
43c28bc
4aebe69
cc2b1eb
8140f5e
1f053a5
beae190
2cdcfb7
d0a93a9
0bed8f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,7 @@ func (r *ServerRoom) MustHaveMembershipForUser(t ct.TestLike, userID, wantMember | |
} | ||
|
||
// ServersInRoom gets all servers currently joined to the room | ||
func (r *ServerRoom) ServersInRoom() (servers []string) { | ||
func (r *ServerRoom) ServersInRoom() (servers []spec.ServerName) { | ||
serverSet := make(map[string]struct{}) | ||
|
||
r.StateMutex.RLock() | ||
|
@@ -282,7 +282,7 @@ func (r *ServerRoom) ServersInRoom() (servers []string) { | |
r.StateMutex.RUnlock() | ||
|
||
for server := range serverSet { | ||
servers = append(servers, server) | ||
servers = append(servers, spec.ServerName(server)) | ||
} | ||
|
||
return | ||
|
@@ -498,21 +498,27 @@ func (i *ServerRoomImplDefault) GenerateSendJoinResponse(room *ServerRoom, s *Se | |
authEvents := room.AuthChainForEvents(stateEvents) | ||
|
||
// get servers in room *before* the join event | ||
serversInRoom := []string{s.serverName} | ||
serversInRoom := []spec.ServerName{s.serverName} | ||
if !omitServersInRoom { | ||
serversInRoom = room.ServersInRoom() | ||
} | ||
|
||
serversInRoomStrings := make([]string, len(serversInRoom)) | ||
for i, serverName := range serversInRoom { | ||
serversInRoomStrings[i] = string(serverName) | ||
} | ||
|
||
// insert the join event into the room state | ||
room.AddEvent(joinEvent) | ||
log.Printf("Received send-join of event %s", joinEvent.EventID()) | ||
|
||
// return state and auth chain | ||
return fclient.RespSendJoin{ | ||
Origin: spec.ServerName(s.serverName), | ||
Origin: s.serverName, | ||
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents), | ||
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents), | ||
MembersOmitted: expectPartialState, | ||
ServersInRoom: serversInRoom, | ||
// TODO: It feels like `ServersInRoom` should be `[]spec.ServerName` instead of `[]string` | ||
ServersInRoom: serversInRoomStrings, | ||
Comment on lines
+521
to
+522
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. This feels like a (not going to fix in this PR) |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"github.com/matrix-org/complement/ct" | ||
"github.com/matrix-org/complement/helpers" | ||
"github.com/matrix-org/gomatrixserverlib" | ||
"github.com/matrix-org/gomatrixserverlib/spec" | ||
) | ||
|
||
// Deployment is the complete instantiation of a Blueprint, with running containers | ||
|
@@ -57,6 +58,16 @@ func (hsDep *HomeserverDeployment) SetEndpoints(baseURL string, fedBaseURL strin | |
} | ||
} | ||
|
||
func (d *Deployment) GetFullyQualifiedHomeserverName(t ct.TestLike, hsName string) spec.ServerName { | ||
_, ok := d.HS[hsName] | ||
if !ok { | ||
ct.Fatalf(t, "Deployment.GetFullyQualifiedHomeserverName - HS name '%s' not found", hsName) | ||
} | ||
// We have network aliases for each Docker container that will resolve the `hsName` to | ||
// the container. | ||
return spec.ServerName(hsName) | ||
} | ||
kegsay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. Currently, I don't think the built-in Complement I'd rather leave it as-is until we need it or at-least do this in a follow-up PR. See the PR description for more context on multiple 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. The PR description doesn't give more context on why multiple
Why would you do this? The 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. @kegsay In the current setup of our custom And we specifically want to test that homeservers between multiple shards can federate with each other as a sanity check (make sure our shards can deploy homeserver tenants correctly): func TestCrossShardFederation(t *testing.T) {
// Create two shards with their own homeserver tenants
shardDeployment1 := complement.Deploy(t, 1)
defer shardDeployment1.Destroy(t)
shardDeployment2 := complement.Deploy(t, 1)
defer shardDeployment2.Destroy(t)
alice := shardDeployment1.Register(t, "hs1", helpers.RegistrationOpts{})
bob := shardDeployment2.Register(t, "hs1", helpers.RegistrationOpts{})
aliceRoomID := alice.MustCreateRoom(t, map[string]any{
"preset": "public_chat",
})
bobRoomID := bob.MustCreateRoom(t, map[string]any{
"preset": "public_chat",
})
t.Run("parallel", func(t *testing.T) {
t.Run("shard1 -> shard2", func(t *testing.T) {
// Since these tests use the same config, they can be run in parallel
t.Parallel()
alice.MustJoinRoom(t, bobRoomID, []string{
shardDeployment2.GetFullyQualifiedHomeserverName(t, "hs1"),
})
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, bobRoomID))
})
t.Run("shard2 -> shard1", func(t *testing.T) {
// Since these tests use the same config, they can be run in parallel
t.Parallel()
bob.MustJoinRoom(t, aliceRoomID, []string{
shardDeployment1.GetFullyQualifiedHomeserverName(t, "hs1"),
})
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, aliceRoomID))
})
})
} This does assume that each Better way to go about this? One alternative I can think of is to bake this information into the Another is to statically assign each homeserver to a shard like |
||
// DestroyAtCleanup destroys the entire deployment. It should be called at cleanup time for dirty | ||
// deployments only. Handles configuration options for things which should run at container destroy | ||
// time, like post-run scripts and printing logs. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
"github.com/matrix-org/complement/helpers" | ||
"github.com/matrix-org/complement/match" | ||
"github.com/matrix-org/complement/must" | ||
"github.com/matrix-org/gomatrixserverlib/spec" | ||
) | ||
|
||
func TestPresence(t *testing.T) { | ||
|
@@ -27,7 +28,9 @@ func TestPresence(t *testing.T) { | |
|
||
// to share presence alice and bob must be in a shared room | ||
roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) | ||
bob.MustJoinRoom(t, roomID, []string{"hs1"}) | ||
bob.MustJoinRoom(t, roomID, []spec.ServerName{ | ||
deployment.GetFullyQualifiedHomeserverName(t, "hs1"), | ||
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. For the reviewer: I've tried to be thorough in updating everything on this list (from the PR description). This would be the main thing to think about. Are there other spots that we need to use
I've also reviewed the diff itself to ensure that I didn't accidentally swap |
||
}) | ||
|
||
// sytest: GET /presence/:user_id/status fetches initial status | ||
t.Run("GET /presence/:user_id/status fetches initial status", func(t *testing.T) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Basically, wherever we expect people to use
deployment.GetFullyQualifiedHomeserverName(t, hsName)
, I've updated these function signatures to acceptspec.ServerName
instead of just plain strings.I also think this is more semantically correct for the places because this needs to be a resolvable homeserver address in the federation.