This commit is contained in:
Albert Skalt 2023-03-11 19:55:31 +03:00 committed by Fedor Korotkiy
parent 1668afb989
commit df663b1b5b

View file

@ -55,6 +55,24 @@ func TestSimpleLimitCancel(t *testing.T) {
require.Equal(t, context.DeadlineExceeded, err) require.Equal(t, context.DeadlineExceeded, err)
} }
func TestAcquireAfterDelay(t *testing.T) {
defer goleak.VerifyNone(t)
e := 2
N := 5
limit := NewLimiter(N, time.Second)
defer limit.Stop()
for epoch := 0; epoch < e; epoch++ {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
for i := 0; i < N; i++ {
require.NoError(t, limit.Acquire(ctx))
}
cancel()
time.Sleep(time.Second * 2)
}
}
func TestAcquireAfterStopped(t *testing.T) { func TestAcquireAfterStopped(t *testing.T) {
defer goleak.VerifyNone(t) defer goleak.VerifyNone(t)