Merge pull request #1362 from FrancoisWagner/fix-data-race-in-hooks-test-pkg

Fix data race in hooks.test package
This commit is contained in:
Simon Eskildsen 2023-01-07 17:04:39 -05:00 committed by GitHub
commit a448f8228b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -32,7 +32,7 @@ func NewGlobal() *Hook {
func NewLocal(logger *logrus.Logger) *Hook {
hook := new(Hook)
logger.Hooks.Add(hook)
logger.AddHook(hook)
return hook

View File

@ -83,3 +83,22 @@ func TestFatalWithAlternateExit(t *testing.T) {
assert.Equal("something went very wrong", hook.LastEntry().Message)
assert.Equal(1, len(hook.Entries))
}
func TestNewLocal(t *testing.T) {
assert := assert.New(t)
logger := logrus.New()
var wg sync.WaitGroup
defer wg.Wait()
wg.Add(10)
for i := 0; i < 10; i++ {
go func(i int) {
logger.Info("info")
wg.Done()
}(i)
}
hook := NewLocal(logger)
assert.NotNil(hook)
}