Add test for race condition in hooks

This commit is contained in:
Aditya Mukerjee
2017-08-04 13:00:10 -04:00
parent 3d1341ce2c
commit 66230b2871
+20
View File
@@ -1,6 +1,7 @@
package logrus
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
@@ -120,3 +121,22 @@ func TestErrorHookShouldFireOnError(t *testing.T) {
assert.Equal(t, hook.Fired, true)
})
}
func TestAddHookRace(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
hook := new(ErrorHook)
LogAndAssertJSON(t, func(log *Logger) {
go func() {
defer wg.Done()
log.AddHook(hook)
}()
go func() {
defer wg.Done()
log.Error("test")
}()
wg.Wait()
}, func(fields Fields) {
assert.Equal(t, hook.Fired, true)
})
}