Skip to content

Commit

Permalink
Merge pull request #1362 from FrancoisWagner/fix-data-race-in-hooks-t…
Browse files Browse the repository at this point in the history
…est-pkg

Fix data race in hooks.test package
  • Loading branch information
sirupsen authored Jan 7, 2023
2 parents f8bf765 + ff07b25 commit a448f82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hooks/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions hooks/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a448f82

Please sign in to comment.