Improve call limiter test

This commit is contained in:
Daniel 2023-10-03 11:35:07 +02:00
parent 3232f2d644
commit 918841e7ea

View file

@ -62,10 +62,30 @@ func TestCallLimiter(t *testing.T) {
} }
testWg.Wait() testWg.Wait()
if execs <= 8 { if execs <= 5 {
t.Errorf("unexpected low exec count: %d", execs) t.Errorf("unexpected low exec count: %d", execs)
} }
if execs >= 12 { if execs >= 15 {
t.Errorf("unexpected high exec count: %d", execs) t.Errorf("unexpected high exec count: %d", execs)
} }
// Wait for pause to reset.
time.Sleep(pause)
// Check if the limiter correctly handles panics.
testWg.Add(100)
for i := 0; i < 100; i++ {
go func() {
defer func() {
_ = recover()
testWg.Done()
}()
oa.Do(func() {
time.Sleep(1 * time.Millisecond)
panic("test")
})
}()
time.Sleep(100 * time.Microsecond)
}
testWg.Wait()
} }