Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-11-01 20:50:01 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-11-01 20:50:01 +0300
commit35c52c2476db8524f5d4e3c2c402522e449d74ef (patch)
tree566d35e2e84817beaa103ca6e77461846460c604 /internal/ratelimiter/ratelimiter_test.go
parent2b5f9c3202c73306a6d7bafb58b7570b7dfec87d (diff)
refactor: make internal/lru and internal/ratelimiter metrics optional
Diffstat (limited to 'internal/ratelimiter/ratelimiter_test.go')
-rw-r--r--internal/ratelimiter/ratelimiter_test.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/internal/ratelimiter/ratelimiter_test.go b/internal/ratelimiter/ratelimiter_test.go
index 03393fb0..5fb9ef2b 100644
--- a/internal/ratelimiter/ratelimiter_test.go
+++ b/internal/ratelimiter/ratelimiter_test.go
@@ -7,6 +7,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
+
+ "gitlab.com/gitlab-org/gitlab-pages/internal/lru"
)
var (
@@ -48,11 +50,13 @@ var sharedTestCases = map[string]struct {
func TestSourceIPAllowed(t *testing.T) {
t.Parallel()
- blocked, cachedEntries, cacheReqs := newTestMetrics(t)
-
for tn, tc := range sharedTestCases {
t.Run(tn, func(t *testing.T) {
- rl := New(blocked, cachedEntries, cacheReqs,
+ rl := New(
+ lru.New("source_ip",
+ lru.DefaultSourceIPItems,
+ lru.DefaultSourceIPExpirationInterval,
+ ),
WithNow(mockNow),
WithSourceIPLimitPerSecond(tc.sourceIPLimit),
WithSourceIPBurstSize(tc.sourceIPBurstSize),
@@ -74,9 +78,12 @@ func TestSourceIPAllowed(t *testing.T) {
func TestSingleRateLimiterWithMultipleSourceIPs(t *testing.T) {
rate := 10 * time.Millisecond
- blocked, cachedEntries, cacheReqs := newTestMetrics(t)
- rl := New(blocked, cachedEntries, cacheReqs,
+ rl := New(
+ lru.New("source_ip",
+ lru.DefaultSourceIPItems,
+ lru.DefaultSourceIPExpirationInterval,
+ ),
WithSourceIPLimitPerSecond(float64(1/rate)),
WithSourceIPBurstSize(1),
)