Add test for ratelimit

This commit is contained in:
pkositsyn 2021-03-15 00:41:45 +03:00 committed by Fedor Korotkiy
parent d515ae871d
commit 1c69d01a8e

View file

@ -55,6 +55,22 @@ func TestSimpleLimitCancel(t *testing.T) {
require.Equal(t, context.DeadlineExceeded, err) require.Equal(t, context.DeadlineExceeded, err)
} }
func TestAcquireAfterStopped(t *testing.T) {
defer goleak.VerifyNone(t)
const nTries = 100
limit := NewLimiter(1, 0)
limit.Stop()
ctx, cancel := context.WithCancel(context.Background())
cancel()
for i := 0; i < nTries; i++ {
require.Equal(t, ErrStopped, limit.Acquire(ctx))
}
}
func TestTimeDistribution(t *testing.T) { func TestTimeDistribution(t *testing.T) {
defer goleak.VerifyNone(t) defer goleak.VerifyNone(t)