Skip to content

Commit

Permalink
store/bucket: clean up tests
Browse files Browse the repository at this point in the history
Only leave the property tests in place since they catch all of the
errors.
  • Loading branch information
Giedrius Statkevičius committed May 22, 2019
1 parent 55aa32d commit 3fe4217
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 145 deletions.
2 changes: 1 addition & 1 deletion pkg/query/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestQueryableCreator_MaxResolution(t *testing.T) {
testProxy := &storeServer{resps: []*storepb.SeriesResponse{}}
queryableCreator := NewQueryableCreator(nil, testProxy, "test")

oneHourMillis := int64(1*time.Hour) / (1000 * 1000)
oneHourMillis := int64(1*time.Hour) / int64(time.Millisecond)
queryable := queryableCreator(false, oneHourMillis, false, func(err error) {})

q, err := queryable.Querier(context.Background(), 0, 42)
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ func int64index(s []int64, x int64) int {
}

// getFor returns a time-ordered list of blocks that cover date between mint and maxt.
// Blocks with the lowest resolution possible but not lower than the given resolution are returned.
// Blocks with the biggest resolution possible but not bigger than the given max resolution are returned.
func (s *bucketBlockSet) getFor(mint, maxt, maxResolutionMillis int64) (bs []*bucketBlock) {
if mint == maxt {
return nil
Expand Down
143 changes: 0 additions & 143 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,149 +156,6 @@ func TestBucketBlock_Property(t *testing.T) {
properties.TestingRun(t)
}

// TestBucketBlockSet with blocks which have the same time range
// but different resolutions.
func TestBucketBlockSet_Duplicated(t *testing.T) {
defer leaktest.CheckTimeout(t, 10*time.Second)()

set := newBucketBlockSet(labels.Labels{})

type resBlock struct {
mint, maxt int64
window int64
}
input := []resBlock{
{window: downsample.ResLevel2, mint: 0, maxt: 100},
{window: downsample.ResLevel0, mint: 0, maxt: 100},
{window: downsample.ResLevel1, mint: 0, maxt: 100},
{window: downsample.ResLevel0, mint: 100, maxt: 200},
{window: downsample.ResLevel1, mint: 100, maxt: 200},
{window: downsample.ResLevel2, mint: 100, maxt: 200},
{window: downsample.ResLevel2, mint: 200, maxt: 300},
{window: downsample.ResLevel1, mint: 200, maxt: 300},
}

for _, in := range input {
var m metadata.Meta
m.Thanos.Downsample.Resolution = in.window
m.MinTime = in.mint
m.MaxTime = in.maxt

testutil.Ok(t, set.add(&bucketBlock{meta: &m}))
}

cases := []struct {
mint, maxt int64
maxResolution int64
res []resBlock
}{
{
mint: 0,
maxt: 300,
maxResolution: downsample.ResLevel2,
res: []resBlock{
{window: downsample.ResLevel2, mint: 0, maxt: 100},
{window: downsample.ResLevel2, mint: 100, maxt: 200},
{window: downsample.ResLevel2, mint: 200, maxt: 300},
},
},
}

for i, c := range cases {
t.Logf("case %d", i)

var exp []*bucketBlock
for _, b := range c.res {
var m metadata.Meta
m.Thanos.Downsample.Resolution = b.window
m.MinTime = b.mint
m.MaxTime = b.maxt
exp = append(exp, &bucketBlock{meta: &m})
}
res := set.getFor(c.mint, c.maxt, c.maxResolution)
testutil.Equals(t, exp, res)
}
}

// TestBucketBlockSet with blocks with different resolutions
// that interleave between each other.
func TestBucketBlockSet_Interleaved(t *testing.T) {
defer leaktest.CheckTimeout(t, 10*time.Second)()

set := newBucketBlockSet(labels.Labels{})

type resBlock struct {
mint, maxt int64
window int64
}
input := []resBlock{
{window: downsample.ResLevel2, mint: 0, maxt: 50},
{window: downsample.ResLevel1, mint: 50, maxt: 100},
{window: downsample.ResLevel2, mint: 100, maxt: 200},
{window: downsample.ResLevel1, mint: 200, maxt: 300},
{window: downsample.ResLevel1, mint: 300, maxt: 400},
{window: downsample.ResLevel1, mint: 400, maxt: 500},
{window: downsample.ResLevel0, mint: 500, maxt: 600},
{window: downsample.ResLevel0, mint: 600, maxt: 700},
}

for _, in := range input {
var m metadata.Meta
m.Thanos.Downsample.Resolution = in.window
m.MinTime = in.mint
m.MaxTime = in.maxt

testutil.Ok(t, set.add(&bucketBlock{meta: &m}))
}

cases := []struct {
mint, maxt int64
maxResolution int64
res []resBlock
}{
{
mint: 0,
maxt: 700,
maxResolution: downsample.ResLevel2,
res: []resBlock{
{window: downsample.ResLevel2, mint: 0, maxt: 50},
{window: downsample.ResLevel1, mint: 50, maxt: 100},
{window: downsample.ResLevel2, mint: 100, maxt: 200},
{window: downsample.ResLevel1, mint: 200, maxt: 300},
{window: downsample.ResLevel1, mint: 300, maxt: 400},
{window: downsample.ResLevel1, mint: 400, maxt: 500},
{window: downsample.ResLevel0, mint: 500, maxt: 600},
{window: downsample.ResLevel0, mint: 600, maxt: 700},
},
},
{
mint: 100,
maxt: 400,
maxResolution: downsample.ResLevel2,
res: []resBlock{
{window: downsample.ResLevel2, mint: 100, maxt: 200},
{window: downsample.ResLevel1, mint: 200, maxt: 300},
{window: downsample.ResLevel1, mint: 300, maxt: 400},
},
},
}

for i, c := range cases {
t.Logf("case %d", i)

var exp []*bucketBlock
for _, b := range c.res {
var m metadata.Meta
m.Thanos.Downsample.Resolution = b.window
m.MinTime = b.mint
m.MaxTime = b.maxt
exp = append(exp, &bucketBlock{meta: &m})
}
res := set.getFor(c.mint, c.maxt, c.maxResolution)
testutil.Equals(t, exp, res)
}
}

func TestBucketBlockSet_addGet(t *testing.T) {
defer leaktest.CheckTimeout(t, 10*time.Second)()

Expand Down

0 comments on commit 3fe4217

Please sign in to comment.