Add test for race condition in hooks
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package logrus
|
package logrus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -120,3 +121,22 @@ func TestErrorHookShouldFireOnError(t *testing.T) {
|
|||||||
assert.Equal(t, hook.Fired, true)
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user