Skip to content

Commit

Permalink
Fix random seed for TestRandom
Browse files Browse the repository at this point in the history
The closure passed to t.Run captured the loop variable which would
always be equal to `*randomN` once the tests started running. This meant
that all of the runs used the same random seed.
  • Loading branch information
BarrensZeppelin committed Jan 12, 2023
1 parent bdfdabc commit bda5726
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions immutable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,7 @@ func RunRandom(t *testing.T, name string, fn func(t *testing.T, rand *rand.Rand)
}
t.Run(name, func(t *testing.T) {
for i := 0; i < *randomN; i++ {
i := i
t.Run(fmt.Sprintf("%08d", i), func(t *testing.T) {
t.Parallel()
fn(t, rand.New(rand.NewSource(int64(i))))
Expand Down

0 comments on commit bda5726

Please sign in to comment.