Skip to content

Commit 62ca6a6

Browse files
authored
Generate unique room IDs when creating rooms (#491)
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.
1 parent f4eebb1 commit 62ca6a6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/federation/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ func (s *Server) MustMakeRoom(t *testing.T, roomVer gomatrixserverlib.RoomVersio
161161
if !s.listening {
162162
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!")
163163
}
164-
roomID := fmt.Sprintf("!%d:%s", len(s.rooms), s.serverName)
164+
// Generate a unique room ID, prefixed with an incrementing counter.
165+
// This ensures that room IDs are not re-used across tests, even if a Complement server happens
166+
// to re-use the same port as a previous one, which
167+
// * reduces noise when searching through logs and
168+
// * prevents homeservers from getting confused when multiple test cases re-use the same homeserver deployment.
169+
roomID := fmt.Sprintf("!%d-%s:%s", len(s.rooms), util.RandomString(18), s.serverName)
165170
t.Logf("Creating room %s with version %s", roomID, roomVer)
166171
room := newRoom(roomVer, roomID)
167172

0 commit comments

Comments
 (0)