diff --git a/block_test.go b/block_test.go index 690cd07ad1..0764d74906 100644 --- a/block_test.go +++ b/block_test.go @@ -20,7 +20,6 @@ import ( "testing" "github.com/prometheus/tsdb/index" - "github.com/prometheus/tsdb/testutil" ) func TestSetCompactionFailed(t *testing.T) { diff --git a/index/index_test.go b/index/index_test.go index 83b6ef6574..dbaf9fdac6 100644 --- a/index/index_test.go +++ b/index/index_test.go @@ -20,8 +20,10 @@ import ( "path/filepath" "sort" "testing" + "unsafe" "github.com/pkg/errors" + "github.com/prometheus/prometheus/pkg/textparse" "github.com/prometheus/tsdb/chunkenc" "github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/labels" @@ -380,3 +382,41 @@ func TestPersistence_index_e2e(t *testing.T) { testutil.Ok(t, ir.Close()) } + +func readPrometheusLabels(fn string, n int) ([]labels.Labels, error) { + f, err := os.Open(fn) + if err != nil { + return nil, err + } + defer f.Close() + + b, err := ioutil.ReadAll(f) + if err != nil { + return nil, err + } + + p := textparse.New(b) + i := 0 + var mets []labels.Labels + hashes := map[uint64]struct{}{} + + for p.Next() && i < n { + m := make(labels.Labels, 0, 10) + p.Metric((*promlabels.Labels)(unsafe.Pointer(&m))) + + h := m.Hash() + if _, ok := hashes[h]; ok { + continue + } + mets = append(mets, m) + hashes[h] = struct{}{} + i++ + } + if err := p.Err(); err != nil { + return nil, err + } + if i != n { + return mets, errors.Errorf("requested %d metrics but found %d", n, i) + } + return mets, nil +} diff --git a/querier_test.go b/querier_test.go index 88b8f088e2..2eb10471c2 100644 --- a/querier_test.go +++ b/querier_test.go @@ -1338,7 +1338,7 @@ func TestDeletedIterator(t *testing.T) { } } - testutil.Assert(t, i < 1000 == true, "") + testutil.Assert(t, i < 1000, "") ts, v := it.At() testutil.Equals(t, act[i].t, ts) @@ -1353,7 +1353,7 @@ func TestDeletedIterator(t *testing.T) { } } - testutil.Assert(t, i < 1000 == false, "") + testutil.Assert(t, i >= 1000, "") testutil.Ok(t, it.Err()) } }