From e359ba111e3182c9f966714314ba5e40b6e51a95 Mon Sep 17 00:00:00 2001 From: rht Date: Wed, 18 Nov 2015 16:03:00 +0700 Subject: [PATCH] Simplify BalancedLayout test License: MIT Signed-off-by: rht --- importer/balanced/balanced_test.go | 88 +++++++----------------------- importer/helpers/dagbuilder.go | 1 - 2 files changed, 21 insertions(+), 68 deletions(-) diff --git a/importer/balanced/balanced_test.go b/importer/balanced/balanced_test.go index 947867cb68c..b47fa0f9918 100644 --- a/importer/balanced/balanced_test.go +++ b/importer/balanced/balanced_test.go @@ -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) { diff --git a/importer/helpers/dagbuilder.go b/importer/helpers/dagbuilder.go index bec8d41063a..4f2875a4c22 100644 --- a/importer/helpers/dagbuilder.go +++ b/importer/helpers/dagbuilder.go @@ -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 }