Commit cbf45fd2 authored by Steven Allen's avatar Steven Allen

test: avoid fuzzing while the race detector is enabled

It's too slow.
parent 03118146
//+build !race
package chunk
import (
"testing"
)
func TestFuzzBuzhashChunking(t *testing.T) {
buf := make([]byte, 1024*1024*16)
for i := 0; i < 100; i++ {
testBuzhashChunking(t, buf)
}
}
...@@ -8,50 +8,50 @@ import ( ...@@ -8,50 +8,50 @@ import (
util "github.com/ipfs/go-ipfs-util" util "github.com/ipfs/go-ipfs-util"
) )
func TestBuzhashChunking(t *testing.T) { func testBuzhashChunking(t *testing.T, buf []byte) (chunkCount int) {
data := make([]byte, 1024*1024*16) util.NewTimeSeededRand().Read(buf)
chunkCount := 0
rounds := 100
for i := 0; i < rounds; i++ { r := NewBuzhash(bytes.NewReader(buf))
util.NewTimeSeededRand().Read(data)
r := NewBuzhash(bytes.NewReader(data)) var chunks [][]byte
var chunks [][]byte for {
chunk, err := r.NextBytes()
for { if err != nil {
chunk, err := r.NextBytes() if err == io.EOF {
if err != nil { break
if err == io.EOF {
break
}
t.Fatal(err)
} }
t.Fatal(err)
chunks = append(chunks, chunk)
} }
chunkCount += len(chunks)
for i, chunk := range chunks { chunks = append(chunks, chunk)
if len(chunk) == 0 { }
t.Fatalf("chunk %d/%d is empty", i+1, len(chunks)) chunkCount += len(chunks)
}
}
for i, chunk := range chunks[:len(chunks)-1] { for i, chunk := range chunks {
if len(chunk) < buzMin { if len(chunk) == 0 {
t.Fatalf("chunk %d/%d is less than the minimum size", i+1, len(chunks)) t.Fatalf("chunk %d/%d is empty", i+1, len(chunks))
}
} }
}
unchunked := bytes.Join(chunks, nil) for i, chunk := range chunks[:len(chunks)-1] {
if !bytes.Equal(unchunked, data) { if len(chunk) < buzMin {
t.Fatal("data was chunked incorrectly") t.Fatalf("chunk %d/%d is less than the minimum size", i+1, len(chunks))
} }
} }
t.Logf("average block size: %d\n", len(data)*rounds/chunkCount)
unchunked := bytes.Join(chunks, nil)
if !bytes.Equal(unchunked, buf) {
t.Fatal("data was chunked incorrectly")
}
return chunkCount
}
func TestBuzhashChunking(t *testing.T) {
buf := make([]byte, 1024*1024*16)
count := testBuzhashChunking(t, buf)
t.Logf("average block size: %d\n", len(buf)/count)
} }
func TestBuzhashChunkReuse(t *testing.T) { func TestBuzhashChunkReuse(t *testing.T) {
......
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