(b *testing.B)
| 247 | } |
| 248 | |
| 249 | func BenchmarkSampler_CheckWithHook(b *testing.B) { |
| 250 | hook, dropped, sampled := makeSamplerCountingHook() |
| 251 | for _, keys := range counterTestCases { |
| 252 | b.Run(fmt.Sprintf("%v keys", len(keys)), func(b *testing.B) { |
| 253 | fac := NewSamplerWithOptions( |
| 254 | NewCore( |
| 255 | NewJSONEncoder(testEncoderConfig()), |
| 256 | &ztest.Discarder{}, |
| 257 | DebugLevel, |
| 258 | ), |
| 259 | time.Millisecond, |
| 260 | 1, |
| 261 | 1000, |
| 262 | SamplerHook(hook), |
| 263 | ) |
| 264 | b.ResetTimer() |
| 265 | b.RunParallel(func(pb *testing.PB) { |
| 266 | i := 0 |
| 267 | for pb.Next() { |
| 268 | ent := Entry{ |
| 269 | Level: DebugLevel + Level(i%4), |
| 270 | Message: keys[i], |
| 271 | } |
| 272 | _ = fac.Check(ent, nil) |
| 273 | i++ |
| 274 | if n := len(keys); i >= n { |
| 275 | i -= n |
| 276 | } |
| 277 | } |
| 278 | }) |
| 279 | // We expect to see 1000 dropped messages for every sampled per settings, |
| 280 | // with a delta due to less 1000 messages getting dropped after initial one |
| 281 | // is sampled. |
| 282 | assert.Greater(b, dropped.Load()/1000, sampled.Load()-1000) |
| 283 | dropped.Store(0) |
| 284 | sampled.Store(0) |
| 285 | }) |
| 286 | } |
| 287 | } |
nothing calls this directly
no test coverage detected