MCPcopy
hub / github.com/uber-go/zap / TestLazyCoreRace

Function TestLazyCoreRace

zapcore/lazy_with_test.go:192–219  ·  view source on GitHub ↗

TestLazyCoreRace tests concurrent access to lazyWithCore methods This is a regression test for issue #1426

(t *testing.T)

Source from the content-addressed store, hash-verified

190// TestLazyCoreRace tests concurrent access to lazyWithCore methods
191// This is a regression test for issue #1426
192func TestLazyCoreRace(t *testing.T) {
193 core, _ := observer.New(zapcore.InfoLevel)
194 lazyCore := zapcore.NewLazyWith(core, []zapcore.Field{
195 makeInt64Field("lazy", 42),
196 })
197
198 var wg sync.WaitGroup
199 const numGoroutines = 50
200
201 // Test concurrent access to Enabled() method which was the source of the race
202 for i := 0; i < numGoroutines; i++ {
203 wg.Add(1)
204 go func() {
205 defer wg.Done()
206
207 // These operations should not race
208 _ = lazyCore.Enabled(zapcore.InfoLevel)
209 _ = lazyCore.Enabled(zapcore.DebugLevel)
210
211 // Also test other methods for good measure
212 if ce := lazyCore.Check(zapcore.Entry{Level: zapcore.InfoLevel, Message: "test"}, nil); ce != nil {
213 _ = lazyCore.Write(zapcore.Entry{Level: zapcore.InfoLevel, Message: "test"}, nil)
214 }
215 }()
216 }
217
218 wg.Wait()
219}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewLazyWithFunction · 0.92
makeInt64FieldFunction · 0.85
EnabledMethod · 0.65
CheckMethod · 0.65
WriteMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected