Skip to content

Commit

Permalink
Update test to verify no sampling & fatal+1 level
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Jun 30, 2021
1 parent 605a517 commit dabfb23
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions zapcore/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,22 @@ func TestSamplerRaces(t *testing.T) {
wg.Wait()
}

func TestSamplerBounds(t *testing.T) {
// Prove that out-of-bounds levels don't crash.
sampler, _ := fakeSampler(DebugLevel-1, time.Minute, 2, 3)
writeSequence(sampler, 1, DebugLevel-1)
func TestSamplerUnknownLevels(t *testing.T) {
// Prove that out-of-bounds levels don't panic.
unknownLevels := []Level{
DebugLevel - 1,
FatalLevel + 1,
}

for _, lvl := range unknownLevels {
t.Run(lvl.String(), func(t *testing.T) {
sampler, logs := fakeSampler(lvl, time.Minute, 2, 3)
for i := 1; i < 10; i++ {
writeSequence(sampler, i, lvl)
}

// Expect no sampling for unknown levels.
assertSequence(t, logs.TakeAll(), lvl, 1, 2, 3, 4, 5, 6, 7, 8, 9)
})
}
}

0 comments on commit dabfb23

Please sign in to comment.