From a2a09ff2750eaf445c07f20aa41abb1e69f94a89 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Thu, 8 Aug 2024 16:44:14 +0200 Subject: [PATCH] Benchmark: Close redis client on each test iteration (-count=10) --- httprateredis.go | 4 ++++ httprateredis_test.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/httprateredis.go b/httprateredis.go index f36e6cb..28b0fda 100644 --- a/httprateredis.go +++ b/httprateredis.go @@ -182,6 +182,10 @@ func (c *redisCounter) IsFallbackActivated() bool { return c.fallbackActivated.Load() } +func (c *redisCounter) Close() error { + return c.client.Close() +} + func (c *redisCounter) shouldFallback(err error) bool { if err == nil { return false diff --git a/httprateredis_test.go b/httprateredis_test.go index 3818c5a..a6b4820 100644 --- a/httprateredis_test.go +++ b/httprateredis_test.go @@ -26,6 +26,7 @@ func TestRedisCounter(t *testing.T) { if err != nil { t.Fatalf("redis not available: %v", err) } + defer limitCounter.Close() limitCounter.Config(1000, time.Minute) @@ -166,6 +167,7 @@ func BenchmarkLocalCounter(b *testing.B) { if err != nil { b.Fatalf("redis not available: %v", err) } + defer limitCounter.Close() limitCounter.Config(1000, time.Minute)