Skip to content

Commit

Permalink
Simplify BalancedLayout test
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
  • Loading branch information
rht committed Nov 18, 2015
1 parent cdcc5bd commit 2a5b06b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 68 deletions.
88 changes: 21 additions & 67 deletions importer/balanced/balanced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion importer/helpers/dagbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2a5b06b

Please sign in to comment.