Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Dec 4, 2023
1 parent 685b1fd commit 411bd4b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 104 deletions.
5 changes: 2 additions & 3 deletions pkg/querier/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/cortexproject/cortex/pkg/cortexpb"
"github.com/cortexproject/cortex/pkg/ingester/client"
"github.com/cortexproject/cortex/pkg/prom1/storage/metric"
"github.com/cortexproject/cortex/pkg/purger"
"github.com/cortexproject/cortex/pkg/querier/batch"
"github.com/cortexproject/cortex/pkg/querier/iterators"
"github.com/cortexproject/cortex/pkg/tenant"
Expand Down Expand Up @@ -278,7 +277,7 @@ func TestShouldSortSeriesIfQueryingMultipleQueryables(t *testing.T) {
for _, queriable := range tc.storeQueriables {
wQueriables = append(wQueriables, &wrappedSampleAndChunkQueryable{QueryableWithFilter: queriable})
}
queryable := NewQueryable(wDistributorQueriable, wQueriables, batch.NewChunkMergeIterator, cfg, overrides, purger.NewNoopTombstonesLoader())
queryable := NewQueryable(wDistributorQueriable, wQueriables, batch.NewChunkMergeIterator, cfg, overrides)
opts := promql.EngineOpts{
Logger: log.NewNopLogger(),
MaxSamples: 1e6,
Expand Down Expand Up @@ -487,7 +486,7 @@ func TestLimits(t *testing.T) {
overrides, err := validation.NewOverrides(DefaultLimitsConfig(), tc.tenantLimit)
require.NoError(t, err)

queryable := NewQueryable(wDistributorQueriable, wQueriables, batch.NewChunkMergeIterator, cfg, overrides, purger.NewNoopTombstonesLoader())
queryable := NewQueryable(wDistributorQueriable, wQueriables, batch.NewChunkMergeIterator, cfg, overrides)
opts := promql.EngineOpts{
Logger: log.NewNopLogger(),
MaxSamples: 1e6,
Expand Down
101 changes: 0 additions & 101 deletions pkg/querier/series/series_set_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package series

import (
"math/rand"
"testing"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -56,102 +54,3 @@ func TestMatrixToSeriesSetSortsMetricLabels(t *testing.T) {
{Name: "g", Value: "h"},
}, l)
}

func TestDeletedSeriesIterator(t *testing.T) {
t.Parallel()
cs := ConcreteSeries{labels: labels.FromStrings("foo", "bar")}
// Insert random stuff from (0, 1000).
for i := 0; i < 1000; i++ {
cs.samples = append(cs.samples, model.SamplePair{Timestamp: model.Time(i), Value: model.SampleValue(rand.Float64())})
}

cases := []struct {
r []model.Interval
}{
{r: []model.Interval{{Start: 1, End: 20}}},
{r: []model.Interval{{Start: 1, End: 10}, {Start: 12, End: 20}, {Start: 21, End: 23}, {Start: 25, End: 30}}},
{r: []model.Interval{{Start: 1, End: 10}, {Start: 12, End: 20}, {Start: 20, End: 30}}},
{r: []model.Interval{{Start: 1, End: 10}, {Start: 12, End: 23}, {Start: 25, End: 30}}},
{r: []model.Interval{{Start: 1, End: 23}, {Start: 12, End: 20}, {Start: 25, End: 30}}},
{r: []model.Interval{{Start: 1, End: 23}, {Start: 12, End: 20}, {Start: 25, End: 3000}}},
{r: []model.Interval{{Start: 0, End: 2000}}},
{r: []model.Interval{{Start: 500, End: 2000}}},
{r: []model.Interval{{Start: 0, End: 200}}},
{r: []model.Interval{{Start: 1000, End: 20000}}},
}

for _, c := range cases {
i := int64(-1)
it := NewDeletedSeriesIterator(NewConcreteSeriesIterator(&cs), c.r)
ranges := c.r[:]

for it.Next() != chunkenc.ValNone {
i++
for _, tr := range ranges {
if inbound(model.Time(i), tr) {
i = int64(tr.End + 1)
ranges = ranges[1:]
}
}

require.Equal(t, true, i < 1000)

ts, v := it.At()
require.Equal(t, int64(cs.samples[i].Timestamp), ts)
require.Equal(t, float64(cs.samples[i].Value), v)
}

// There has been an extra call to Next().
i++
for _, tr := range ranges {
if inbound(model.Time(i), tr) {
i = int64(tr.End + 1)
ranges = ranges[1:]
}
}

require.Equal(t, true, i >= 1000)
require.NoError(t, it.Err())
}
}

func TestDeletedIterator_WithSeek(t *testing.T) {
t.Parallel()
cs := ConcreteSeries{labels: labels.FromStrings("foo", "bar")}
// Insert random stuff from (0, 1000).
for i := 0; i < 1000; i++ {
cs.samples = append(cs.samples, model.SamplePair{Timestamp: model.Time(i), Value: model.SampleValue(rand.Float64())})
}

cases := []struct {
r []model.Interval
seek int64
ok bool
seekedTs int64
}{
{r: []model.Interval{{Start: 1, End: 20}}, seek: 1, ok: true, seekedTs: 21},
{r: []model.Interval{{Start: 1, End: 20}}, seek: 20, ok: true, seekedTs: 21},
{r: []model.Interval{{Start: 1, End: 20}}, seek: 10, ok: true, seekedTs: 21},
{r: []model.Interval{{Start: 1, End: 20}}, seek: 999, ok: true, seekedTs: 999},
{r: []model.Interval{{Start: 1, End: 20}}, seek: 1000, ok: false},
{r: []model.Interval{{Start: 1, End: 23}, {Start: 24, End: 40}, {Start: 45, End: 3000}}, seek: 1, ok: true, seekedTs: 41},
{r: []model.Interval{{Start: 5, End: 23}, {Start: 24, End: 40}, {Start: 41, End: 3000}}, seek: 5, ok: false},
{r: []model.Interval{{Start: 0, End: 2000}}, seek: 10, ok: false},
{r: []model.Interval{{Start: 500, End: 2000}}, seek: 10, ok: true, seekedTs: 10},
{r: []model.Interval{{Start: 500, End: 2000}}, seek: 501, ok: false},
}

for _, c := range cases {
it := NewDeletedSeriesIterator(NewConcreteSeriesIterator(&cs), c.r)

require.NotEqual(t, c.ok, it.Seek(c.seek), chunkenc.ValNone)
if c.ok {
ts, _ := it.At()
require.Equal(t, c.seekedTs, ts)
}
}
}

func inbound(t model.Time, interval model.Interval) bool {
return interval.Start <= t && t <= interval.End
}

0 comments on commit 411bd4b

Please sign in to comment.