From 9973facd6a4a23a09e8fc357da8dcec116393290 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Wed, 4 Dec 2024 12:22:16 -0500 Subject: [PATCH] Faster tests using the mocked consul in-memory backend (#624) Signed-off-by: Marco Pracucci --- kv/consul/mock.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kv/consul/mock.go b/kv/consul/mock.go index e2f434b61..ec848e135 100644 --- a/kv/consul/mock.go +++ b/kv/consul/mock.go @@ -15,6 +15,9 @@ import ( "github.com/grafana/dskit/kv/codec" ) +// The max wait time allowed for mockKV operations, in order to have faster tests. +const maxWaitTime = 100 * time.Millisecond + type mockKV struct { mtx sync.Mutex cond *sync.Cond @@ -87,7 +90,7 @@ func (m *mockKV) loop() { select { case <-m.close: return - case <-time.After(time.Second): + case <-time.After(maxWaitTime): m.mtx.Lock() m.cond.Broadcast() m.mtx.Unlock() @@ -258,7 +261,6 @@ func (m *mockKV) ResetIndexForKey(key string) { // mockedMaxWaitTime returns the minimum duration between the input duration // and the max wait time allowed in this mock, in order to have faster tests. func mockedMaxWaitTime(queryWaitTime time.Duration) time.Duration { - const maxWaitTime = time.Second if queryWaitTime > maxWaitTime { return maxWaitTime }