hooks/test: fix incorrect use of math/rand

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"
This commit is contained in:
Olivier Mengué 2024-03-12 00:24:55 +01:00
parent dd1b4c2e81
commit 857f9242a1
1 changed files with 2 additions and 2 deletions

View File

@ -41,8 +41,8 @@ func TestAllHooks(t *testing.T) {
func TestLoggingWithHooksRace(t *testing.T) { func TestLoggingWithHooksRace(t *testing.T) {
rand.Seed(time.Now().Unix()) r := rand.New(rand.NewSource(time.Now().UnixNano()))
unlocker := rand.Int() % 100 unlocker := r.Intn(100)
assert := assert.New(t) assert := assert.New(t)
logger, hook := NewNullLogger() logger, hook := NewNullLogger()