Reuse testutil (#393)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
pull/5805/head
Ganesh Vernekar 6 years ago committed by Goutham Veeramachaneni
parent 9c8ca47399
commit e779603633

@ -33,9 +33,7 @@ func BenchmarkCreateSeries(b *testing.B) {
testutil.Ok(b, err) testutil.Ok(b, err)
h, err := NewHead(nil, nil, nil, 10000) h, err := NewHead(nil, nil, nil, 10000)
if err != nil { testutil.Ok(b, err)
testutil.Ok(b, err)
}
defer h.Close() defer h.Close()
b.ReportAllocs() b.ReportAllocs()

@ -2,7 +2,6 @@ package tsdb
import ( import (
"os" "os"
"reflect"
"testing" "testing"
"github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/chunks"
@ -50,48 +49,32 @@ func TestRepairBadIndexVersion(t *testing.T) {
// In its current state, lookups should fail with the fixed code. // In its current state, lookups should fail with the fixed code.
const dir = "testdata/repair_index_version/01BZJ9WJQPWHGNC2W4J9TA62KC/" const dir = "testdata/repair_index_version/01BZJ9WJQPWHGNC2W4J9TA62KC/"
meta, err := readMetaFile(dir) meta, err := readMetaFile(dir)
if err == nil { testutil.NotOk(t, err)
t.Fatal("error expected but got none")
}
// Touch chunks dir in block. // Touch chunks dir in block.
os.MkdirAll(dir+"chunks", 0777) os.MkdirAll(dir+"chunks", 0777)
r, err := index.NewFileReader(dir + "index") r, err := index.NewFileReader(dir + "index")
if err != nil { testutil.Ok(t, err)
t.Fatal(err)
}
p, err := r.Postings("b", "1") p, err := r.Postings("b", "1")
if err != nil { testutil.Ok(t, err)
t.Fatal(err)
}
for p.Next() { for p.Next() {
t.Logf("next ID %d", p.At()) t.Logf("next ID %d", p.At())
var lset labels.Labels var lset labels.Labels
if err := r.Series(p.At(), &lset, nil); err == nil { testutil.NotOk(t, r.Series(p.At(), &lset, nil))
t.Fatal("expected error but got none")
}
}
if p.Err() != nil {
t.Fatal(err)
} }
testutil.Ok(t, p.Err())
testutil.Ok(t, r.Close()) testutil.Ok(t, r.Close())
// On DB opening all blocks in the base dir should be repaired. // On DB opening all blocks in the base dir should be repaired.
db, err := Open("testdata/repair_index_version", nil, nil, nil) db, err := Open("testdata/repair_index_version", nil, nil, nil)
if err != nil { testutil.Ok(t, err)
t.Fatal(err)
}
db.Close() db.Close()
r, err = index.NewFileReader(dir + "index") r, err = index.NewFileReader(dir + "index")
if err != nil { testutil.Ok(t, err)
t.Fatal(err)
}
p, err = r.Postings("b", "1") p, err = r.Postings("b", "1")
if err != nil { testutil.Ok(t, err)
t.Fatal(err)
}
res := []labels.Labels{} res := []labels.Labels{}
for p.Next() { for p.Next() {
@ -99,26 +82,17 @@ func TestRepairBadIndexVersion(t *testing.T) {
var lset labels.Labels var lset labels.Labels
var chks []chunks.Meta var chks []chunks.Meta
if err := r.Series(p.At(), &lset, &chks); err != nil { testutil.Ok(t, r.Series(p.At(), &lset, &chks))
t.Fatal(err)
}
res = append(res, lset) res = append(res, lset)
} }
if p.Err() != nil {
t.Fatal(err) testutil.Ok(t, p.Err())
} testutil.Equals(t, []labels.Labels{
if !reflect.DeepEqual(res, []labels.Labels{
{{"a", "1"}, {"b", "1"}}, {{"a", "1"}, {"b", "1"}},
{{"a", "2"}, {"b", "1"}}, {{"a", "2"}, {"b", "1"}},
}) { }, res)
t.Fatalf("unexpected result %v", res)
}
meta, err = readMetaFile(dir) meta, err = readMetaFile(dir)
if err != nil { testutil.Ok(t, err)
t.Fatal(err) testutil.Assert(t, meta.Version == 1, "unexpected meta version %d", meta.Version)
}
if meta.Version != 1 {
t.Fatalf("unexpected meta version %d", meta.Version)
}
} }

Loading…
Cancel
Save