fix race condition for SetFormatter and properly fix SetReportCaller race as well
This commit is contained in:
@@ -269,6 +269,12 @@ func TestEntryLogfLevel(t *testing.T) {
|
||||
func TestEntryReportCallerRace(t *testing.T) {
|
||||
logger := New()
|
||||
entry := NewEntry(logger)
|
||||
|
||||
// logging before SetReportCaller has the highest chance of causing a race condition
|
||||
// to be detected, but doing it twice just to increase the likelyhood of detecting the race
|
||||
go func() {
|
||||
entry.Info("should not race")
|
||||
}()
|
||||
go func() {
|
||||
logger.SetReportCaller(true)
|
||||
}()
|
||||
@@ -276,3 +282,20 @@ func TestEntryReportCallerRace(t *testing.T) {
|
||||
entry.Info("should not race")
|
||||
}()
|
||||
}
|
||||
|
||||
func TestEntryFormatterRace(t *testing.T) {
|
||||
logger := New()
|
||||
entry := NewEntry(logger)
|
||||
|
||||
// logging before SetReportCaller has the highest chance of causing a race condition
|
||||
// to be detected, but doing it twice just to increase the likelyhood of detecting the race
|
||||
go func() {
|
||||
entry.Info("should not race")
|
||||
}()
|
||||
go func() {
|
||||
logger.SetFormatter(&TextFormatter{})
|
||||
}()
|
||||
go func() {
|
||||
entry.Info("should not race")
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user