Skip to content

Commit 34e2015

Browse files
committed
Update Redis in CI, lower #no of requests
1 parent a2a09ff commit 34e2015

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111

1212
services:
1313
redis:
14-
image: redis:6
14+
image: redis:7
1515
ports:
1616
- 6379:6379
1717

httprateredis_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func TestRedisCounter(t *testing.T) {
1515
limitCounter, err := httprateredis.NewRedisLimitCounter(&httprateredis.Config{
1616
Host: "localhost",
1717
Port: 6379,
18-
MaxIdle: 100,
19-
MaxActive: 200,
18+
MaxIdle: 0,
19+
MaxActive: 2,
2020
DBIndex: 0,
2121
ClientName: "httprateredis_test",
2222
PrefixKey: fmt.Sprintf("httprate:test:%v", rand.Int31n(100000)), // Unique Redis key for each test
@@ -162,7 +162,10 @@ func BenchmarkLocalCounter(b *testing.B) {
162162
DBIndex: 0,
163163
ClientName: "httprateredis_test",
164164
PrefixKey: fmt.Sprintf("httprate:test:%v", rand.Int31n(100000)), // Unique key for each test
165+
MaxActive: 10,
166+
MaxIdle: 0,
165167
FallbackDisabled: true,
168+
FallbackTimeout: 5 * time.Second,
166169
})
167170
if err != nil {
168171
b.Fatalf("redis not available: %v", err)
@@ -174,6 +177,8 @@ func BenchmarkLocalCounter(b *testing.B) {
174177
currentWindow := time.Now().UTC().Truncate(time.Minute)
175178
previousWindow := currentWindow.Add(-time.Minute)
176179

180+
concurrentRequests := 100
181+
177182
b.ResetTimer()
178183

179184
for i := 0; i < b.N; i++ {
@@ -183,14 +188,14 @@ func BenchmarkLocalCounter(b *testing.B) {
183188
previousWindow.Add(time.Duration(i) * time.Minute)
184189

185190
wg := sync.WaitGroup{}
186-
wg.Add(1000)
187-
for i := 0; i < 1000; i++ {
191+
wg.Add(concurrentRequests)
192+
for i := 0; i < concurrentRequests; i++ {
188193
// Simulate concurrent requests with different rate-limit keys.
189194
go func(i int) {
190195
defer wg.Done()
191196

192197
_, _, _ = limitCounter.Get(fmt.Sprintf("key:%v", i), currentWindow, previousWindow)
193-
_ = limitCounter.IncrementBy(fmt.Sprintf("key:%v", i), currentWindow, rand.Intn(100))
198+
_ = limitCounter.IncrementBy(fmt.Sprintf("key:%v", i), currentWindow, rand.Intn(20))
194199
}(i)
195200
}
196201
wg.Wait()

0 commit comments

Comments
 (0)