Commit 89ba9942 authored by rht's avatar rht Committed by Jeromy

Simplify BalancedLayout test

License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent b4a38541
...@@ -49,13 +49,11 @@ func TestSizeBasedSplit(t *testing.T) { ...@@ -49,13 +49,11 @@ func TestSizeBasedSplit(t *testing.T) {
t.SkipNow() t.SkipNow()
} }
bs := chunk.SizeSplitterGen(512) testFileConsistency(t, 32*512, 512)
testFileConsistency(t, bs, 32*512) testFileConsistency(t, 32*4096, 4096)
bs = chunk.SizeSplitterGen(4096)
testFileConsistency(t, bs, 32*4096)
// Uneven offset // Uneven offset
testFileConsistency(t, bs, 31*4095) testFileConsistency(t, 31*4095, 4096)
} }
func dup(b []byte) []byte { func dup(b []byte) []byte {
...@@ -64,51 +62,20 @@ func dup(b []byte) []byte { ...@@ -64,51 +62,20 @@ func dup(b []byte) []byte {
return o return o
} }
func testFileConsistency(t *testing.T, bs chunk.SplitterGen, nbytes int) { func testFileConsistency(t *testing.T, nbytes int64, blksize int64) {
should := make([]byte, nbytes)
u.NewTimeSeededRand().Read(should)
read := bytes.NewReader(should)
ds := mdtest.Mock() ds := mdtest.Mock()
nd, err := buildTestDag(ds, bs(read)) nd, should := getTestDag(t, ds, nbytes, blksize)
if err != nil {
t.Fatal(err)
}
r, err := uio.NewDagReader(context.Background(), nd, ds) r, err := uio.NewDagReader(context.Background(), nd, ds)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
out, err := ioutil.ReadAll(r) dagrArrComp(t, r, should)
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should)
if err != nil {
t.Fatal(err)
}
} }
func TestBuilderConsistency(t *testing.T) { func TestBuilderConsistency(t *testing.T) {
dagserv := mdtest.Mock() testFileConsistency(t, 100000, chunk.DefaultBlockSize)
nd, should := getTestDag(t, dagserv, 100000, chunk.DefaultBlockSize)
r, err := uio.NewDagReader(context.Background(), nd, dagserv)
if err != nil {
t.Fatal(err)
}
out, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should)
if err != nil {
t.Fatal(err)
}
} }
func arrComp(a, b []byte) error { func arrComp(a, b []byte) error {
...@@ -123,6 +90,17 @@ func arrComp(a, b []byte) error { ...@@ -123,6 +90,17 @@ func arrComp(a, b []byte) error {
return nil return nil
} }
func dagrArrComp(t *testing.T, r io.Reader, should []byte) {
out, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}
if err := arrComp(out, should); err != nil {
t.Fatal(err)
}
}
type dagservAndPinner struct { type dagservAndPinner struct {
ds dag.DAGService ds dag.DAGService
mp pin.Pinner mp pin.Pinner
...@@ -166,15 +144,7 @@ func TestSeekingBasic(t *testing.T) { ...@@ -166,15 +144,7 @@ func TestSeekingBasic(t *testing.T) {
t.Fatal("Failed to seek to correct offset") t.Fatal("Failed to seek to correct offset")
} }
out, err := ioutil.ReadAll(rs) dagrArrComp(t, rs, should[start:])
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should[start:])
if err != nil {
t.Fatal(err)
}
} }
func TestSeekToBegin(t *testing.T) { func TestSeekToBegin(t *testing.T) {
...@@ -202,15 +172,7 @@ func TestSeekToBegin(t *testing.T) { ...@@ -202,15 +172,7 @@ func TestSeekToBegin(t *testing.T) {
t.Fatal("Failed to seek to beginning") t.Fatal("Failed to seek to beginning")
} }
out, err := ioutil.ReadAll(rs) dagrArrComp(t, rs, should)
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should)
if err != nil {
t.Fatal(err)
}
} }
func TestSeekToAlmostBegin(t *testing.T) { func TestSeekToAlmostBegin(t *testing.T) {
...@@ -238,15 +200,7 @@ func TestSeekToAlmostBegin(t *testing.T) { ...@@ -238,15 +200,7 @@ func TestSeekToAlmostBegin(t *testing.T) {
t.Fatal("Failed to seek to almost beginning") t.Fatal("Failed to seek to almost beginning")
} }
out, err := ioutil.ReadAll(rs) dagrArrComp(t, rs, should[1:])
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should[1:])
if err != nil {
t.Fatal(err)
}
} }
func TestSeekEnd(t *testing.T) { func TestSeekEnd(t *testing.T) {
......
...@@ -52,7 +52,6 @@ func (db *DagBuilderHelper) prepareNext() { ...@@ -52,7 +52,6 @@ func (db *DagBuilderHelper) prepareNext() {
func (db *DagBuilderHelper) Done() bool { func (db *DagBuilderHelper) Done() bool {
// ensure we have an accurate perspective on data // ensure we have an accurate perspective on data
// as `done` this may be called before `next`. // as `done` this may be called before `next`.
//db.prepareNext() // idempotent
db.prepareNext() // idempotent db.prepareNext() // idempotent
return db.nextData == nil return db.nextData == nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment