aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/storage_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'syncapi/storage/storage_test.go')
-rw-r--r--syncapi/storage/storage_test.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/syncapi/storage/storage_test.go b/syncapi/storage/storage_test.go
index f57b0d61..ce7ca3fc 100644
--- a/syncapi/storage/storage_test.go
+++ b/syncapi/storage/storage_test.go
@@ -213,12 +213,48 @@ func TestGetEventsInRangeWithTopologyToken(t *testing.T) {
// backpaginate 5 messages starting at the latest position.
filter := &synctypes.RoomEventFilter{Limit: 5}
- paginatedEvents, err := snapshot.GetEventsInTopologicalRange(ctx, &from, &to, r.ID, filter, true)
+ paginatedEvents, start, end, err := snapshot.GetEventsInTopologicalRange(ctx, &from, &to, r.ID, filter, true)
if err != nil {
t.Fatalf("GetEventsInTopologicalRange returned an error: %s", err)
}
gots := snapshot.StreamEventsToEvents(context.Background(), nil, paginatedEvents, nil)
test.AssertEventsEqual(t, gots, test.Reversed(events[len(events)-5:]))
+ assert.Equal(t, types.TopologyToken{Depth: 15, PDUPosition: 15}, start)
+ assert.Equal(t, types.TopologyToken{Depth: 11, PDUPosition: 11}, end)
+ })
+ })
+}
+
+// The purpose of this test is to ensure that backfilling returns no start/end if a given filter removes
+// all events.
+func TestGetEventsInRangeWithTopologyTokenNoEventsForFilter(t *testing.T) {
+ test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
+ db, close := MustCreateDatabase(t, dbType)
+ defer close()
+ alice := test.NewUser(t)
+ r := test.NewRoom(t, alice)
+ for i := 0; i < 10; i++ {
+ r.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{"body": fmt.Sprintf("hi %d", i)})
+ }
+ events := r.Events()
+ _ = MustWriteEvents(t, db, events)
+
+ WithSnapshot(t, db, func(snapshot storage.DatabaseTransaction) {
+ from := types.TopologyToken{Depth: math.MaxInt64, PDUPosition: math.MaxInt64}
+ t.Logf("max topo pos = %+v", from)
+ // head towards the beginning of time
+ to := types.TopologyToken{}
+
+ // backpaginate 20 messages starting at the latest position.
+ notTypes := []string{spec.MRoomRedaction}
+ senders := []string{alice.ID}
+ filter := &synctypes.RoomEventFilter{Limit: 20, NotTypes: &notTypes, Senders: &senders}
+ paginatedEvents, start, end, err := snapshot.GetEventsInTopologicalRange(ctx, &from, &to, r.ID, filter, true)
+ assert.NoError(t, err)
+ assert.Equal(t, 0, len(paginatedEvents))
+ // Even if we didn't get anything back due to the filter, we should still have start/end
+ assert.Equal(t, types.TopologyToken{Depth: 15, PDUPosition: 15}, start)
+ assert.Equal(t, types.TopologyToken{Depth: 1, PDUPosition: 1}, end)
})
})
}