Skip to content

Commit

Permalink
Faster tests using the mocked consul in-memory backend (#624)
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci authored Dec 4, 2024
1 parent 77bb9dd commit 9973fac
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kv/consul/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 9973fac

Please sign in to comment.