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

Function TestSamplerWithZeroThereafter

zapcore/sampler_test.go:292–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

290}
291
292func TestSamplerWithZeroThereafter(t *testing.T) {
293 var counter countingCore
294
295 // Logs two messages per second.
296 sampler := NewSamplerWithOptions(&counter, time.Second, 2, 0)
297
298 now := time.Now()
299
300 for i := 0; i < 1000; i++ {
301 ent := Entry{
302 Level: InfoLevel,
303 Message: "msg",
304 Time: now,
305 }
306 if ce := sampler.Check(ent, nil); ce != nil {
307 ce.Write()
308 }
309 }
310
311 assert.Equal(t, 2, int(counter.logs.Load()),
312 "Unexpected number of logs")
313
314 now = now.Add(time.Second)
315
316 for i := 0; i < 1000; i++ {
317 ent := Entry{
318 Level: InfoLevel,
319 Message: "msg",
320 Time: now,
321 }
322 if ce := sampler.Check(ent, nil); ce != nil {
323 ce.Write()
324 }
325 }
326
327 assert.Equal(t, 4, int(counter.logs.Load()),
328 "Unexpected number of logs")
329}

Callers

nothing calls this directly

Calls 5

NewSamplerWithOptionsFunction · 0.85
NowMethod · 0.65
CheckMethod · 0.65
WriteMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected