From 857f9242a17d844dda11986016a0e256d35eb7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Tue, 12 Mar 2024 00:24:55 +0100 Subject: [PATCH] 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" --- hooks/test/test_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/test/test_test.go b/hooks/test/test_test.go index 9601491..e4e5127 100644 --- a/hooks/test/test_test.go +++ b/hooks/test/test_test.go @@ -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()