Skip to content

Commit

Permalink
Generate unique room IDs when creating rooms (#491)
Browse files Browse the repository at this point in the history
This ensures that room IDs are not re-used across tests, even if a
Complement server happens to re-use the same port as a previous one,
which reduces noise when searching through logs and prevents homeservers
from getting confused when multiple test cases re-use the same
homeserver deployment.
  • Loading branch information
squahtx authored Oct 6, 2022
1 parent f4eebb1 commit 62ca6a6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/federation/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ func (s *Server) MustMakeRoom(t *testing.T, roomVer gomatrixserverlib.RoomVersio
if !s.listening {
s.t.Fatalf("MustMakeRoom() called before Listen() - this is not supported because Listen() chooses a high-numbered port and thus changes the server name and thus changes the room ID. Ensure you Listen() first!")
}
roomID := fmt.Sprintf("!%d:%s", len(s.rooms), s.serverName)
// Generate a unique room ID, prefixed with an incrementing counter.
// This ensures that room IDs are not re-used across tests, even if a Complement server happens
// to re-use the same port as a previous one, which
// * reduces noise when searching through logs and
// * prevents homeservers from getting confused when multiple test cases re-use the same homeserver deployment.
roomID := fmt.Sprintf("!%d-%s:%s", len(s.rooms), util.RandomString(18), s.serverName)
t.Logf("Creating room %s with version %s", roomID, roomVer)
room := newRoom(roomVer, roomID)

Expand Down

0 comments on commit 62ca6a6

Please sign in to comment.