Skip to content

Commit

Permalink
hooks/test: fix incorrect use of math/rand
Browse files Browse the repository at this point in the history
Fix incorrect uses of math/rand:
- do not call rand.Seed() in a test as it affects the global pseudo-random number
  generator and might affect other tests (or Logrus itself). Instead, use a local
  instance of a number generator
- seed with time.Now().UnixNano() instead of time.Now().Unix() for more
  randomness
- use "rand.Intn(100)" instead of "rand.Int() % 100"
  • Loading branch information
dolmen committed Mar 11, 2024
1 parent dd1b4c2 commit 857f924
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hooks/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestAllHooks(t *testing.T) {

func TestLoggingWithHooksRace(t *testing.T) {

rand.Seed(time.Now().Unix())
unlocker := rand.Int() % 100
r := rand.New(rand.NewSource(time.Now().UnixNano()))
unlocker := r.Intn(100)

assert := assert.New(t)
logger, hook := NewNullLogger()
Expand Down

0 comments on commit 857f924

Please sign in to comment.