From df663b1b5b8ec68cfebbf18e4de0bc0a6e231aec Mon Sep 17 00:00:00 2001 From: Albert Skalt Date: Sat, 11 Mar 2023 19:55:31 +0300 Subject: [PATCH] Add test --- ratelimit/ratelimit_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ratelimit/ratelimit_test.go b/ratelimit/ratelimit_test.go index 96a4a65..7f6555a 100644 --- a/ratelimit/ratelimit_test.go +++ b/ratelimit/ratelimit_test.go @@ -55,6 +55,24 @@ func TestSimpleLimitCancel(t *testing.T) { 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) { defer goleak.VerifyNone(t)