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

Draft: Federation /messages tests #443

Closed
wants to merge 12 commits into from
44 changes: 44 additions & 0 deletions internal/b/blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,47 @@ func manyMessages(senders []string, count int) []Event {
}
return evs
}

func manJoinEvents(homeserver string, users []User) []Event {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func manJoinEvents(homeserver string, users []User) []Event {
func manyJoinEvents(homeserver string, users []User) []Event {

evs := make([]Event, len(users))
for i := 0; i < len(users); i++ {
user := users[i]
evs[i] = Event{
Type: "m.room.member",
StateKey: Ptr(fmt.Sprintf("%s:%s", user.Localpart, homeserver)),
Content: map[string]interface{}{
"membership": "join",
},
Sender: user.Localpart,
}
}
return evs
}

func manyUsers(count int) []User {
users := make([]User, count)

for i := 0; i < count; i++ {
localPart := fmt.Sprintf("@user_%d", i)
displayName := fmt.Sprintf("User %d", i)
deviceID := fmt.Sprintf("USERDEVICE%d", i)

users[i] = User{
Localpart: localPart,
DisplayName: displayName,
OneTimeKeys: 50,
DeviceID: Ptr(deviceID),
}
}

return users
}

func getSendersFromUsers(users []User) []string {
senders := make([]string, len(users))
for i := 0; i < len(users); i++ {
senders[i] = users[i].Localpart
}

return senders
}
19 changes: 0 additions & 19 deletions internal/b/perf_e2ee_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,3 @@ func memberships(count int) []Event {

return events
}

func manyUsers(count int) []User {
users := make([]User, count)

for i := 0; i < count; i++ {
localPart := fmt.Sprintf("@alice_%d", i)
displayName := fmt.Sprintf("Alice %d", i)
deviceID := fmt.Sprintf("ALICEDEVICE%d", i)

users[i] = User{
Localpart: localPart,
DisplayName: displayName,
OneTimeKeys: 50,
DeviceID: Ptr(deviceID),
}
}

return users
}
45 changes: 33 additions & 12 deletions internal/b/perf_many_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,34 @@

package b

var manyUsersList = manyUsers(500)

func makeEvents(homeserver string) []Event {
events := []Event{
{
Type: "m.room.member",
StateKey: Ptr("@bob:hs1"),
Content: map[string]interface{}{
"membership": "join",
},
Sender: "@bob",
},
}
events = append(events, manJoinEvents(homeserver, manyUsersList)...)
events = append(events, manyMessages(getSendersFromUsers(manyUsersList), 1000)...)

//fmt.Printf("events made %d events=%+v", len(events), events)

return events
}

// BlueprintPerfManyMessages contains a homeserver with 2 users, who are joined to the same room with thousands of messages.
var BlueprintPerfManyMessages = MustValidate(Blueprint{
Name: "perf_many_messages",
Homeservers: []Homeserver{
{
Name: "hs1",
Users: []User{
Users: append([]User{
{
Localpart: "@alice",
DisplayName: "Alice",
Expand All @@ -29,23 +50,23 @@ var BlueprintPerfManyMessages = MustValidate(Blueprint{
Localpart: "@bob",
DisplayName: "Bob",
},
},
}, manyUsersList...),
Rooms: []Room{
{
CreateRoom: map[string]interface{}{
"preset": "public_chat",
},
Creator: "@alice",
Events: append([]Event{
Event{
Type: "m.room.member",
StateKey: Ptr("@bob:hs1"),
Content: map[string]interface{}{
"membership": "join",
},
Sender: "@bob",
},
}, manyMessages([]string{"@alice", "@bob"}, 7000)...),
Events: makeEvents("hs1"),
},
},
},
{
Name: "hs2",
Users: []User{
{
Localpart: "@charlie",
DisplayName: "Charlie",
},
},
},
Expand Down
5 changes: 4 additions & 1 deletion internal/docker/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func (d *Builder) ConstructBlueprintIfNotExist(bprint b.Blueprint) error {
return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ImageList: %w", bprint.Name, err)
}
if len(images) == 0 {
d.ConstructBlueprint(bprint)
err := d.ConstructBlueprint(bprint)
if err != nil {
return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to build image: %w", bprint.Name, err)
}
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}
Expand Down
52 changes: 52 additions & 0 deletions tests/federation_room_messages_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tests

import (
"net/url"
"testing"
"time"

"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/client"
"github.com/sirupsen/logrus"
)

func TestMessagesOverFederation(t *testing.T) {
deployment := Deploy(t, b.BlueprintPerfManyMessages)
defer deployment.Destroy(t)

alice := deployment.Client(t, "hs1", "@alice:hs1")

remoteCharlie := deployment.Client(t, "hs2", "@charlie:hs2")

t.Run("parallel", func(t *testing.T) {
t.Run("asdf", func(t *testing.T) {
t.Parallel()

syncResult, _ := alice.MustSync(t, client.SyncReq{})
joinedRooms := syncResult.Get("rooms.join|@keys")
roomWithManyMessages := joinedRooms.Get("0").String()

// logrus.WithFields(logrus.Fields{
// "joinedRooms": joinedRooms,
// "roomWithManyMessages": roomWithManyMessages,
// }).Error("asdf")

remoteCharlie.JoinRoom(t, roomWithManyMessages, []string{"hs1"})

messagesRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomWithManyMessages, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{
"dir": []string{"b"},
"limit": []string{"100"},
}))
messagesResBody := client.ParseJSON(t, messagesRes)
eventIDs := client.GetJSONFieldStringArray(t, messagesResBody, "chunk")

logrus.WithFields(logrus.Fields{
"joinedRooms": joinedRooms,
"roomWithManyMessages": roomWithManyMessages,
"eventIDs": eventIDs,
}).Error("asdf")

time.Sleep(5 * time.Second)
})
})
}