From 1c69d01a8e1196ca7163b801f36b4782ce4a3018 Mon Sep 17 00:00:00 2001 From: pkositsyn Date: Mon, 15 Mar 2021 00:41:45 +0300 Subject: [PATCH] Add test for ratelimit --- ratelimit/ratelimit_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ratelimit/ratelimit_test.go b/ratelimit/ratelimit_test.go index 15c595f..96a4a65 100644 --- a/ratelimit/ratelimit_test.go +++ b/ratelimit/ratelimit_test.go @@ -55,6 +55,22 @@ func TestSimpleLimitCancel(t *testing.T) { 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) { defer goleak.VerifyNone(t)