Always insert a PL event in tests

This commit is contained in:
Kegan Dougal 2022-02-22 10:42:54 +00:00
parent b71a2b7769
commit 8884b2c215
2 changed files with 12 additions and 5 deletions

View File

@ -26,7 +26,6 @@ func TestTimelines(t *testing.T) {
aliceToken := "ALICE_BEARER_TOKEN_TestTimelines"
// make 20 rooms, last room is most recent, and send A,B,C into each room
allRooms := make([]roomEvents, 20)
latestTimestamp := time.Now()
for i := 0; i < len(allRooms); i++ {
ts := time.Now().Add(time.Duration(i) * time.Minute)
roomName := fmt.Sprintf("My Room %d", i)
@ -40,10 +39,8 @@ func TestTimelines(t *testing.T) {
testutils.NewEvent(t, "m.room.message", alice, map[string]interface{}{"body": "C"}, ts.Add(6*time.Second)),
}...),
}
if ts.After(latestTimestamp) {
latestTimestamp = ts
}
}
latestTimestamp := time.Now().Add(10 * time.Hour)
v2.addAccount(alice, aliceToken)
v2.queueResponse(alice, sync2.SyncResponse{
Rooms: sync2.SyncRoomsResponse{

View File

@ -16,6 +16,7 @@ import (
"time"
"github.com/gorilla/mux"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/sync-v3/sync2"
"github.com/matrix-org/sync-v3/sync3"
"github.com/matrix-org/sync-v3/sync3/handler"
@ -92,7 +93,10 @@ func (s *testV2Server) nextResponse(userID string) *sync2.SyncResponse {
}
select {
case data := <-ch:
log.Printf("testV2Server: nextResponse %s returning data", userID)
log.Printf(
"testV2Server: nextResponse %s returning data: [invite=%d,join=%d,leave=%d]",
userID, len(data.Rooms.Invite), len(data.Rooms.Join), len(data.Rooms.Leave),
)
return &data
case <-time.After(1 * time.Second):
log.Printf("testV2Server: nextResponse %s waited >1s for data, returning null", userID)
@ -247,10 +251,16 @@ func runTestServer(t *testing.T, v2Server *testV2Server, postgresConnectionStrin
func createRoomState(t *testing.T, creator string, baseTimestamp time.Time) []json.RawMessage {
t.Helper()
var pl gomatrixserverlib.PowerLevelContent
pl.Defaults()
pl.Users = map[string]int64{
creator: 100,
}
// all with the same timestamp as they get made atomically
return []json.RawMessage{
testutils.NewStateEvent(t, "m.room.create", "", creator, map[string]interface{}{"creator": creator}, testutils.WithTimestamp(baseTimestamp)),
testutils.NewStateEvent(t, "m.room.member", creator, creator, map[string]interface{}{"membership": "join"}, testutils.WithTimestamp(baseTimestamp)),
testutils.NewStateEvent(t, "m.room.power_levels", "", creator, pl, testutils.WithTimestamp(baseTimestamp)),
testutils.NewStateEvent(t, "m.room.join_rules", "", creator, map[string]interface{}{"join_rule": "public"}, testutils.WithTimestamp(baseTimestamp)),
}
}