Skip to content

Commit 1f053a5

Browse files
committed
Finish off srv
1 parent 8140f5e commit 1f053a5

8 files changed

Lines changed: 68 additions & 59 deletions

federation/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,18 @@ func (s *Server) FederationClient(deployment FederationDeployment) fclient.Feder
219219

220220
// MustSendTransaction sends the given PDUs/EDUs to the target destination, returning an error if the /send fails or if the response contains an error
221221
// for any sent PDUs. Times out after 10 seconds.
222-
func (s *Server) MustSendTransaction(t ct.TestLike, deployment FederationDeployment, destination string, pdus []json.RawMessage, edus []gomatrixserverlib.EDU) {
222+
//
223+
// Args:
224+
// - `destination`: This should be a resolvable addresses within the deployment network.
225+
func (s *Server) MustSendTransaction(t ct.TestLike, deployment FederationDeployment, destination spec.ServerName, pdus []json.RawMessage, edus []gomatrixserverlib.EDU) {
223226
t.Helper()
224227
cli := s.FederationClient(deployment)
225228
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
226229
defer cancel()
227230
resp, err := cli.SendTransaction(ctx, gomatrixserverlib.Transaction{
228231
TransactionID: gomatrixserverlib.TransactionID(fmt.Sprintf("complement-%d", time.Now().Nanosecond())),
229232
Origin: spec.ServerName(s.ServerName()),
230-
Destination: spec.ServerName(destination),
233+
Destination: destination,
231234
PDUs: pdus,
232235
EDUs: edus,
233236
})
@@ -320,6 +323,9 @@ func (s *Server) MustCreateEvent(t ct.TestLike, room *ServerRoom, ev Event) goma
320323

321324
// MustJoinRoom will make the server send a make_join and a send_join to join a room
322325
// It returns the resultant room.
326+
//
327+
// Args:
328+
// - `remoteServer`: This should be a resolvable addresses within the deployment network.
323329
func (s *Server) MustJoinRoom(t ct.TestLike, deployment FederationDeployment, remoteServer spec.ServerName, roomID string, userID string, opts ...JoinRoomOpt) *ServerRoom {
324330
t.Helper()
325331
var jr joinRoom
@@ -402,6 +408,9 @@ func (s *Server) MustJoinRoom(t ct.TestLike, deployment FederationDeployment, re
402408
}
403409

404410
// Leaves a room. If this is rejecting an invite then a make_leave request is made first, before send_leave.
411+
//
412+
// Args:
413+
// - `remoteServer`: This should be a resolvable addresses within the deployment network.
405414
func (s *Server) MustLeaveRoom(t ct.TestLike, deployment FederationDeployment, remoteServer spec.ServerName, roomID string, userID string) {
406415
t.Helper()
407416
origin := spec.ServerName(s.serverName)

tests/csapi/sync_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ func TestSync(t *testing.T) {
288288
charlie := srv.UserID("charlie")
289289

290290
redactionRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})
291-
redactionRoom := srv.MustJoinRoom(t, deployment, "hs1", redactionRoomID, charlie)
291+
redactionRoom := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), redactionRoomID, charlie)
292292

293293
sentinelRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})
294-
sentinelRoom := srv.MustJoinRoom(t, deployment, "hs1", sentinelRoomID, charlie)
294+
sentinelRoom := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), sentinelRoomID, charlie)
295295

296296
// charlie creates a bogus redaction, which he sends out, followed by
297297
// a good event - in another room - to act as a sentinel. It's not
@@ -304,7 +304,7 @@ func TestSync(t *testing.T) {
304304
Redacts: "$12345"})
305305
redactionRoom.AddEvent(redactionEvent)
306306
t.Logf("Created redaction event %s", redactionEvent.EventID())
307-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{redactionEvent.JSON()}, nil)
307+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{redactionEvent.JSON()}, nil)
308308

309309
sentinelEvent := srv.MustCreateEvent(t, sentinelRoom, federation.Event{
310310
Type: "m.room.test",
@@ -313,7 +313,7 @@ func TestSync(t *testing.T) {
313313
})
314314
sentinelRoom.AddEvent(sentinelEvent)
315315
t.Logf("Created sentinel event %s", sentinelEvent.EventID())
316-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{redactionEvent.JSON(), sentinelEvent.JSON()}, nil)
316+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{redactionEvent.JSON(), sentinelEvent.JSON()}, nil)
317317

318318
// wait for the sentinel to arrive
319319
nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(sentinelRoomID, sentinelEvent.EventID()))
@@ -332,7 +332,7 @@ func TestSync(t *testing.T) {
332332
pdus[i] = ev.JSON()
333333
lastSentEventId = ev.EventID()
334334
}
335-
srv.MustSendTransaction(t, deployment, "hs1", pdus, nil)
335+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), pdus, nil)
336336
t.Logf("Sent filler events, with final event %s", lastSentEventId)
337337

338338
// sync, starting from the same ?since each time, until the final message turns up.
@@ -463,7 +463,7 @@ func TestSyncTimelineGap(t *testing.T) {
463463
charlie := srv.UserID("charlie")
464464

465465
roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})
466-
room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie)
466+
room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie)
467467

468468
filterID := createFilter(t, alice, map[string]interface{}{
469469
"room": map[string]interface{}{
@@ -515,7 +515,7 @@ func TestSyncTimelineGap(t *testing.T) {
515515
// requests.
516516
respondToGetMissingEventsEndpoints(t, srv, room, missingEvents)
517517

518-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{lastEvent.JSON()}, nil)
518+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{lastEvent.JSON()}, nil)
519519

520520
// We now test two different modes of /sync work. The first is when we are
521521
// syncing when the server receives the `lastEvent` (and so, at least

tests/federation_event_auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestEventAuth(t *testing.T) {
6262
})
6363
room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie)
6464
firstJoinEvent := room.CurrentState("m.room.member", charlie)
65-
srv.MustLeaveRoom(t, deployment, "hs1", roomID, charlie)
65+
srv.MustLeaveRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie)
6666
leaveEvent := room.CurrentState("m.room.member", charlie)
6767
room = srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie)
6868

tests/federation_room_get_missing_events_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestGetMissingEventsGapFilling(t *testing.T) {
127127
).Methods("POST")
128128

129129
// 3) ...and send that alone to the HS.
130-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{mostRecentEvent.JSON()}, nil)
130+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{mostRecentEvent.JSON()}, nil)
131131

132132
// 6) Ensure Alice sees all injected events in the correct order.
133133
correctOrderEventIDs := append([]string{lastSharedEvent.EventID()}, missingEventIDs...)

tests/federation_room_send_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func TestNetworkPartitionOrdering(t *testing.T) {
177177
}
178178

179179
// remote homeserver now injects event 1'
180-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event1prime.JSON()}, nil)
180+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event1prime.JSON()}, nil)
181181

182182
// ensure it gets there
183183
alice.MustSyncUntil(t, client.SyncReq{TimeoutMillis: "1000"}, client.SyncTimelineHasEventID(serverRoom.RoomID, event1prime.EventID()))

tests/federation_sync_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestSyncOmitsStateChangeOnFilteredEvents(t *testing.T) {
8585
})
8686

8787
// fork the dag earlier at e1 and send s2
88-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{s2.JSON()}, nil)
88+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{s2.JSON()}, nil)
8989

9090
// wait until we see S2 to ensure the server has processed this.
9191
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(serverRoom.RoomID, s2.EventID()))

tests/federation_unreject_rejected_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ func TestUnrejectRejectedEvents(t *testing.T) {
6565
// Send event B into the room. Event A at this point is unknown
6666
// to the homeserver and we're not going to respond to the events
6767
// request for it, so it should get rejected.
68-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{eventB.JSON()}, nil)
68+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{eventB.JSON()}, nil)
6969

7070
// Now we're going to send Event A into the room, which should give
7171
// the server the prerequisite event to pass Event B later. This one
7272
// should appear in /sync.
73-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{eventA.JSON()}, nil)
73+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{eventA.JSON()}, nil)
7474

7575
// Wait for event A to appear in the room. We're going to store the
7676
// sync token here because we want to assert on the next sync that
@@ -82,7 +82,7 @@ func TestUnrejectRejectedEvents(t *testing.T) {
8282

8383
// Finally, send Event B again. This time it should be unrejected and
8484
// should be sent as a new event down /sync for the first time.
85-
srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{eventB.JSON()}, nil)
85+
srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{eventB.JSON()}, nil)
8686

8787
// Now see if event B appears in the room. Use the since token from the
8888
// last sync to ensure we're only waiting for new events since event A.

0 commit comments

Comments
 (0)