3 files changed,
13 insertions(+),
10 deletions(-)
Author:
Olexandr Smirnov
ss2316544@gmail.com
Committed by:
GitHub
noreply@github.com
Committed at:
2025-08-24 17:37:08 +0300
Parent:
7ff621d
M
internal/transport/http/ratelimit/ratelimit_test.go
··· 4 4 "net/http" 5 5 "net/http/httptest" 6 6 "testing" 7 + "testing/synctest" 7 8 "time" 8 9 9 10 "github.com/gin-gonic/gin" ··· 23 24 assert.Len(t, limiter.visitors, 1) 24 25 } 25 26 26 -// TODO: rewrite to use "testing/synctest" when it gets merged 27 27 func TestRateLimiter_cleanupVisitors(t *testing.T) { 28 - limiter := newLimiter(10, 20, time.Second/2) 29 - limiter.getVisitor("192.168.9.1") 30 - assert.Len(t, limiter.visitors, 1) 28 + synctest.Test(t, func(t *testing.T) { 29 + limiter := newLimiter(10, 20, time.Minute) 30 + limiter.getVisitor("192.168.9.1") 31 + assert.Len(t, limiter.visitors, 1) 31 32 32 - time.Sleep(time.Second) 33 - limiter.cleanupVisitors() 34 - assert.Empty(t, limiter.visitors) 33 + time.Sleep(61 * time.Second) 34 + 35 + limiter.cleanupVisitors() 36 + assert.Empty(t, limiter.visitors) 37 + }) 35 38 } 36 39 37 40 func TestMiddleware(t *testing.T) {