Skip to content

Commit

Permalink
chunking: a t.Parallel on tests
Browse files Browse the repository at this point in the history
Time went down from 25s to 0.5s

I also removed `TestFuzzBuzhashChunking` since I rewrote it a `testing.F` fuzz test and yet it wasn't able to find any new interesting input.
  • Loading branch information
Jorropo committed Jan 12, 2024
1 parent 651402f commit 922c66c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
14 changes: 0 additions & 14 deletions chunker/buzhash_norace_test.go

This file was deleted.

12 changes: 12 additions & 0 deletions chunker/buzhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func testBuzhashChunking(t *testing.T, buf []byte) (chunkCount int) {
t.Parallel()

n, err := util.NewTimeSeededRand().Read(buf)
if n < len(buf) {
t.Fatalf("expected %d bytes, got %d", len(buf), n)
Expand Down Expand Up @@ -89,3 +91,13 @@ func TestBuzhashBitsHashBias(t *testing.T) {
}
}
}

func FuzzBuzhashChunking(f *testing.F) {
f.Add(make([]byte, 1024*1024*16))
f.Fuzz(func(t *testing.T, b []byte) {
if len(b) < buzMin {
return
}
testBuzhashChunking(t, b)
})
}
4 changes: 4 additions & 0 deletions chunker/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
)

func TestParseRabin(t *testing.T) {
t.Parallel()

r := bytes.NewReader(randBuf(t, 1000))

_, err := FromString(r, "rabin-18-25-32")
Expand Down Expand Up @@ -55,6 +57,8 @@ func TestParseRabin(t *testing.T) {
}

func TestParseSize(t *testing.T) {
t.Parallel()

r := bytes.NewReader(randBuf(t, 1000))

_, err := FromString(r, "size-0")
Expand Down
4 changes: 4 additions & 0 deletions chunker/rabin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

func TestRabinChunking(t *testing.T) {
t.Parallel()

data := make([]byte, 1024*1024*16)
n, err := util.NewTimeSeededRand().Read(data)
if n < len(data) {
Expand Down Expand Up @@ -67,6 +69,8 @@ func chunkData(t *testing.T, newC newSplitter, data []byte) map[string]blocks.Bl
}

func testReuse(t *testing.T, cr newSplitter) {
t.Parallel()

data := make([]byte, 1024*1024*16)
n, err := util.NewTimeSeededRand().Read(data)
if n < len(data) {
Expand Down
4 changes: 4 additions & 0 deletions chunker/splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func copyBuf(buf []byte) []byte {
}

func TestSizeSplitterOverAllocate(t *testing.T) {
t.Parallel()

max := 1000
r := bytes.NewReader(randBuf(t, max))
chunksize := int64(1024 * 256)
Expand All @@ -40,6 +42,7 @@ func TestSizeSplitterIsDeterministic(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()

test := func() {
bufR := randBuf(t, 10000000) // crank this up to satisfy yourself.
Expand Down Expand Up @@ -75,6 +78,7 @@ func TestSizeSplitterFillsChunks(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
t.Parallel()

max := 10000000
b := randBuf(t, max)
Expand Down

0 comments on commit 922c66c

Please sign in to comment.