Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(util) test with many seeds #238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type randGen struct {
src rand.Source
}

func NewFastRand() io.Reader {
func NewFastRand(seed int64) io.Reader {
return &randGen{rand.NewSource(time.Now().UnixNano())}
}

Expand Down
14 changes: 12 additions & 2 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ func TestKey(t *testing.T) {
}

func TestByteChanReader(t *testing.T) {
var numSeedsToTest = 1000
if testing.Short() {
numSeedsToTest = 100
}
for i := 0; i < numSeedsToTest; i++ {
testByteChanReaderWithSeed(int64(i), t)
}
}

func testByteChanReaderWithSeed(seed int64, t *testing.T) {
data := make([]byte, 1024*1024)
r := NewFastRand()
r := NewFastRand(seed)
r.Read(data)
dch := make(chan []byte, 8)

Expand All @@ -55,7 +65,7 @@ func TestByteChanReader(t *testing.T) {
}

if !bytes.Equal(out, data) {
t.Fatal("Reader failed to stream correct bytes")
t.Errorf("Reader failed to stream correct bytes with seed %d", seed)
}
}

Expand Down