Fixup tests

This commit is contained in:
David Robertson 2023-05-24 15:50:53 +01:00
parent 471c0a26eb
commit 4f69909f8b
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
3 changed files with 30 additions and 26 deletions

View File

@ -41,7 +41,7 @@ func addRooms(list *sync3.InternalRequestLists, n int) {
UserRoomData: caches.UserRoomData{ UserRoomData: caches.UserRoomData{
IsDM: next%10 == 0, IsDM: next%10 == 0,
}, },
LastInterestedEventTimestamp: messageTimestamp, LastInterestedEventTimestamps: make(map[string]uint64),
}, true) })
} }
} }

View File

@ -32,6 +32,7 @@ func newFinder(rooms []*RoomConnMetadata) finder {
} }
func TestSortBySingleOperation(t *testing.T) { func TestSortBySingleOperation(t *testing.T) {
const listKey = "my_list"
room1 := "!1:localhost" room1 := "!1:localhost"
room2 := "!2:localhost" room2 := "!2:localhost"
room3 := "!3:localhost" room3 := "!3:localhost"
@ -46,7 +47,7 @@ func TestSortBySingleOperation(t *testing.T) {
NotificationCount: 12, NotificationCount: 12,
CanonicalisedName: "foo", CanonicalisedName: "foo",
}, },
LastInterestedEventTimestamp: 600, LastInterestedEventTimestamps: map[string]uint64{listKey: 600},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -57,7 +58,7 @@ func TestSortBySingleOperation(t *testing.T) {
NotificationCount: 3, NotificationCount: 3,
CanonicalisedName: "koo", CanonicalisedName: "koo",
}, },
LastInterestedEventTimestamp: 700, LastInterestedEventTimestamps: map[string]uint64{listKey: 700},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -68,7 +69,7 @@ func TestSortBySingleOperation(t *testing.T) {
NotificationCount: 7, NotificationCount: 7,
CanonicalisedName: "yoo", CanonicalisedName: "yoo",
}, },
LastInterestedEventTimestamp: 900, LastInterestedEventTimestamps: map[string]uint64{listKey: 900},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -79,7 +80,7 @@ func TestSortBySingleOperation(t *testing.T) {
NotificationCount: 1, NotificationCount: 1,
CanonicalisedName: "boo", CanonicalisedName: "boo",
}, },
LastInterestedEventTimestamp: 800, LastInterestedEventTimestamps: map[string]uint64{listKey: 800},
}, },
} }
// name: 4,1,2,3 // name: 4,1,2,3
@ -95,7 +96,7 @@ func TestSortBySingleOperation(t *testing.T) {
SortByNotificationLevel + " " + SortByRecency: {room3, room4, room1, room2}, SortByNotificationLevel + " " + SortByRecency: {room3, room4, room1, room2},
} }
f := newFinder(rooms) f := newFinder(rooms)
sr := NewSortableRooms(f, f.roomIDs) sr := NewSortableRooms(f, listKey, f.roomIDs)
for sortBy, wantOrder := range wantMap { for sortBy, wantOrder := range wantMap {
sr.Sort(strings.Split(sortBy, " ")) sr.Sort(strings.Split(sortBy, " "))
var gotRoomIDs []string var gotRoomIDs []string
@ -111,6 +112,7 @@ func TestSortBySingleOperation(t *testing.T) {
} }
func TestSortByMultipleOperations(t *testing.T) { func TestSortByMultipleOperations(t *testing.T) {
const listKey = "my_list"
room1 := "!1:localhost" room1 := "!1:localhost"
room2 := "!2:localhost" room2 := "!2:localhost"
room3 := "!3:localhost" room3 := "!3:localhost"
@ -125,7 +127,7 @@ func TestSortByMultipleOperations(t *testing.T) {
NotificationCount: 1, NotificationCount: 1,
CanonicalisedName: "foo", CanonicalisedName: "foo",
}, },
LastInterestedEventTimestamp: 600, LastInterestedEventTimestamps: map[string]uint64{listKey: 600},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -136,7 +138,7 @@ func TestSortByMultipleOperations(t *testing.T) {
NotificationCount: 5, NotificationCount: 5,
CanonicalisedName: "koo", CanonicalisedName: "koo",
}, },
LastInterestedEventTimestamp: 700, LastInterestedEventTimestamps: map[string]uint64{listKey: 700},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -147,7 +149,7 @@ func TestSortByMultipleOperations(t *testing.T) {
NotificationCount: 0, NotificationCount: 0,
CanonicalisedName: "yoo", CanonicalisedName: "yoo",
}, },
LastInterestedEventTimestamp: 800, LastInterestedEventTimestamps: map[string]uint64{listKey: 800},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -158,7 +160,7 @@ func TestSortByMultipleOperations(t *testing.T) {
NotificationCount: 0, NotificationCount: 0,
CanonicalisedName: "boo", CanonicalisedName: "boo",
}, },
LastInterestedEventTimestamp: 900, LastInterestedEventTimestamps: map[string]uint64{listKey: 900},
}, },
} }
testCases := []struct { testCases := []struct {
@ -183,7 +185,7 @@ func TestSortByMultipleOperations(t *testing.T) {
}, },
} }
f := newFinder(rooms) f := newFinder(rooms)
sr := NewSortableRooms(f, f.roomIDs) sr := NewSortableRooms(f, listKey, f.roomIDs)
for _, tc := range testCases { for _, tc := range testCases {
sr.Sort(tc.SortBy) sr.Sort(tc.SortBy)
var gotRoomIDs []string var gotRoomIDs []string
@ -200,6 +202,7 @@ func TestSortByMultipleOperations(t *testing.T) {
// Test that if you remove a room, it updates the lookup map. // Test that if you remove a room, it updates the lookup map.
func TestSortableRoomsRemove(t *testing.T) { func TestSortableRoomsRemove(t *testing.T) {
const listKey = "my_list"
room1 := "!1:localhost" room1 := "!1:localhost"
room2 := "!2:localhost" room2 := "!2:localhost"
rooms := []*RoomConnMetadata{ rooms := []*RoomConnMetadata{
@ -212,7 +215,7 @@ func TestSortableRoomsRemove(t *testing.T) {
NotificationCount: 1, NotificationCount: 1,
CanonicalisedName: "foo", CanonicalisedName: "foo",
}, },
LastInterestedEventTimestamp: 700, LastInterestedEventTimestamps: map[string]uint64{listKey: 700},
}, },
{ {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -223,11 +226,11 @@ func TestSortableRoomsRemove(t *testing.T) {
NotificationCount: 2, NotificationCount: 2,
CanonicalisedName: "foo2", CanonicalisedName: "foo2",
}, },
LastInterestedEventTimestamp: 600, LastInterestedEventTimestamps: map[string]uint64{listKey: 600},
}, },
} }
f := newFinder(rooms) f := newFinder(rooms)
sr := NewSortableRooms(f, f.roomIDs) sr := NewSortableRooms(f, listKey, f.roomIDs)
if err := sr.Sort([]string{SortByRecency}); err != nil { // room 1 is first, then room 2 if err := sr.Sort([]string{SortByRecency}); err != nil { // room 1 is first, then room 2
t.Fatalf("Sort: %s", err) t.Fatalf("Sort: %s", err)
} }
@ -253,6 +256,7 @@ func TestSortableRoomsRemove(t *testing.T) {
// dedicated test as it relies on multiple fields // dedicated test as it relies on multiple fields
func TestSortByNotificationLevel(t *testing.T) { func TestSortByNotificationLevel(t *testing.T) {
const listKey = "my_list"
// create the full set of possible sort variables, most recent message last // create the full set of possible sort variables, most recent message last
roomUnencHC := "!unencrypted-highlight-count:localhost" roomUnencHC := "!unencrypted-highlight-count:localhost"
roomUnencHCNC := "!unencrypted-highlight-and-notif-count:localhost" roomUnencHCNC := "!unencrypted-highlight-and-notif-count:localhost"
@ -271,7 +275,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 1, HighlightCount: 1,
NotificationCount: 0, NotificationCount: 0,
}, },
LastInterestedEventTimestamp: 1, LastInterestedEventTimestamps: map[string]uint64{listKey: 1},
}, },
roomUnencHCNC: { roomUnencHCNC: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -281,7 +285,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 1, HighlightCount: 1,
NotificationCount: 1, NotificationCount: 1,
}, },
LastInterestedEventTimestamp: 2, LastInterestedEventTimestamps: map[string]uint64{listKey: 2},
}, },
roomUnencNC: { roomUnencNC: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -291,7 +295,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 0, HighlightCount: 0,
NotificationCount: 1, NotificationCount: 1,
}, },
LastInterestedEventTimestamp: 3, LastInterestedEventTimestamps: map[string]uint64{listKey: 3},
}, },
roomUnenc: { roomUnenc: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -301,7 +305,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 0, HighlightCount: 0,
NotificationCount: 0, NotificationCount: 0,
}, },
LastInterestedEventTimestamp: 4, LastInterestedEventTimestamps: map[string]uint64{listKey: 4},
}, },
roomEncHC: { roomEncHC: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -311,7 +315,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 1, HighlightCount: 1,
NotificationCount: 0, NotificationCount: 0,
}, },
LastInterestedEventTimestamp: 5, LastInterestedEventTimestamps: map[string]uint64{listKey: 5},
}, },
roomEncHCNC: { roomEncHCNC: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -321,7 +325,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 1, HighlightCount: 1,
NotificationCount: 1, NotificationCount: 1,
}, },
LastInterestedEventTimestamp: 6, LastInterestedEventTimestamps: map[string]uint64{listKey: 6},
}, },
roomEncNC: { roomEncNC: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -332,7 +336,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 0, HighlightCount: 0,
NotificationCount: 1, NotificationCount: 1,
}, },
LastInterestedEventTimestamp: 7, LastInterestedEventTimestamps: map[string]uint64{listKey: 7},
}, },
roomEnc: { roomEnc: {
RoomMetadata: internal.RoomMetadata{ RoomMetadata: internal.RoomMetadata{
@ -343,7 +347,7 @@ func TestSortByNotificationLevel(t *testing.T) {
HighlightCount: 0, HighlightCount: 0,
NotificationCount: 0, NotificationCount: 0,
}, },
LastInterestedEventTimestamp: 8, LastInterestedEventTimestamps: map[string]uint64{listKey: 8},
}, },
} }
roomIDs := make([]string, len(roomsMap)) roomIDs := make([]string, len(roomsMap))
@ -357,7 +361,7 @@ func TestSortByNotificationLevel(t *testing.T) {
} }
t.Logf("%v", roomIDs) t.Logf("%v", roomIDs)
f := newFinder(rooms) f := newFinder(rooms)
sr := NewSortableRooms(f, roomIDs) sr := NewSortableRooms(f, listKey, roomIDs)
if err := sr.Sort([]string{SortByNotificationLevel, SortByRecency}); err != nil { if err := sr.Sort([]string{SortByNotificationLevel, SortByRecency}); err != nil {
t.Fatalf("Sort: %s", err) t.Fatalf("Sort: %s", err)
} }

View File

@ -907,12 +907,12 @@ func TestBumpEventTypesHandling(t *testing.T) {
RequiredState: [][2]string{{"m.room.avatar", ""}, {"m.room.encryption", ""}}, RequiredState: [][2]string{{"m.room.avatar", ""}, {"m.room.encryption", ""}},
TimelineLimit: 10, TimelineLimit: 10,
}, },
BumpEventTypes: []string{"m.room.message", "m.room.encrypted"},
} }
aliceSyncRequest := sync3.Request{ aliceSyncRequest := sync3.Request{
Lists: map[string]sync3.RequestList{ Lists: map[string]sync3.RequestList{
"alice_list": aliceReqList, "alice_list": aliceReqList,
}, },
BumpEventTypes: []string{"m.room.message", "m.room.encrypted"},
} }
// This sync should include both of Bob's messages. The proxy will make an initial // This sync should include both of Bob's messages. The proxy will make an initial
// V2 sync to the HS, which should include the latest event in both rooms. // V2 sync to the HS, which should include the latest event in both rooms.
@ -936,12 +936,12 @@ func TestBumpEventTypesHandling(t *testing.T) {
RequiredState: [][2]string{{"m.room.avatar", ""}, {"m.room.encryption", ""}}, RequiredState: [][2]string{{"m.room.avatar", ""}, {"m.room.encryption", ""}},
TimelineLimit: 10, TimelineLimit: 10,
}, },
BumpEventTypes: []string{"m.room.message", "m.room.encrypted", "m.room.member"},
} }
bobSyncRequest := sync3.Request{ bobSyncRequest := sync3.Request{
Lists: map[string]sync3.RequestList{ Lists: map[string]sync3.RequestList{
"bob_list": bobReqList, "bob_list": bobReqList,
}, },
BumpEventTypes: []string{"m.room.message", "m.room.encrypted", "m.room.member"},
} }
bobRes := bob.SlidingSync(t, bobSyncRequest) bobRes := bob.SlidingSync(t, bobSyncRequest)