Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster tests using the mocked consul in-memory backend #624

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading