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) {
t.SkipNow()
}
bs := chunk.SizeSplitterGen(512)
testFileConsistency(t, bs, 32*512)
bs = chunk.SizeSplitterGen(4096)
testFileConsistency(t, bs, 32*4096)
testFileConsistency(t, 32*512, 512)
testFileConsistency(t, 32*4096, 4096)
// Uneven offset
testFileConsistency(t, bs, 31*4095)
testFileConsistency(t, 31*4095, 4096)
}
func dup(b []byte) []byte {
......@@ -64,51 +62,20 @@ func dup(b []byte) []byte {
return o
}
func testFileConsistency(t *testing.T, bs chunk.SplitterGen, nbytes int) {
should := make([]byte, nbytes)
u.NewTimeSeededRand().Read(should)
read := bytes.NewReader(should)
func testFileConsistency(t *testing.T, nbytes int64, blksize int64) {
ds := mdtest.Mock()
nd, err := buildTestDag(ds, bs(read))
if err != nil {
t.Fatal(err)
}
nd, should := getTestDag(t, ds, nbytes, blksize)
r, err := uio.NewDagReader(context.Background(), nd, ds)
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)
}
dagrArrComp(t, r, should)
}
func TestBuilderConsistency(t *testing.T) {
dagserv := mdtest.Mock()
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)
}
testFileConsistency(t, 100000, chunk.DefaultBlockSize)
}
func arrComp(a, b []byte) error {
......@@ -123,6 +90,17 @@ func arrComp(a, b []byte) error {
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 {
ds dag.DAGService
mp pin.Pinner
......@@ -166,15 +144,7 @@ func TestSeekingBasic(t *testing.T) {
t.Fatal("Failed to seek to correct offset")
}
out, err := ioutil.ReadAll(rs)
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should[start:])
if err != nil {
t.Fatal(err)
}
dagrArrComp(t, rs, should[start:])
}
func TestSeekToBegin(t *testing.T) {
......@@ -202,15 +172,7 @@ func TestSeekToBegin(t *testing.T) {
t.Fatal("Failed to seek to beginning")
}
out, err := ioutil.ReadAll(rs)
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should)
if err != nil {
t.Fatal(err)
}
dagrArrComp(t, rs, should)
}
func TestSeekToAlmostBegin(t *testing.T) {
......@@ -238,15 +200,7 @@ func TestSeekToAlmostBegin(t *testing.T) {
t.Fatal("Failed to seek to almost beginning")
}
out, err := ioutil.ReadAll(rs)
if err != nil {
t.Fatal(err)
}
err = arrComp(out, should[1:])
if err != nil {
t.Fatal(err)
}
dagrArrComp(t, rs, should[1:])
}
func TestSeekEnd(t *testing.T) {
......
......@@ -52,7 +52,6 @@ func (db *DagBuilderHelper) prepareNext() {
func (db *DagBuilderHelper) Done() bool {
// ensure we have an accurate perspective on data
// as `done` this may be called before `next`.
//db.prepareNext() // idempotent
db.prepareNext() // idempotent
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