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

test: Fix for a few data races #12129

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions pkg/querier/ingester_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package querier
import (
"context"
"errors"
"go.uber.org/atomic"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -65,6 +66,8 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {
},
}

var cnt atomic.Int32

for testName, testData := range tests {
for _, retErr := range []bool{true, false} {
testName, testData, retErr := testName, testData, retErr
Expand All @@ -75,9 +78,9 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {
}

t.Run(testName, func(t *testing.T) {
cnt := 0
wg := sync.WaitGroup{}
wait := make(chan struct{})
cnt.Store(0)

runFn := func(args mock.Arguments) {
wg.Done()
Expand All @@ -88,7 +91,7 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {
// ctx should be cancelled after the first two replicas return
require.ErrorIs(t, ctx.Err(), context.Canceled)
case <-wait:
cnt++
cnt.Add(1)
case <-time.After(time.Second):
t.Error("timed out waiting for ctx cancellation")
}
Expand Down Expand Up @@ -121,7 +124,7 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {

err = testData.testFn(ingesterQuerier)
ingesterClient.AssertNumberOfCalls(t, testData.method, 3)
require.Equal(t, 2, cnt)
require.Equal(t, int32(2), cnt.Load())
if retErr {
require.ErrorContains(t, err, testData.method+" failed")
} else {
Expand Down Expand Up @@ -176,7 +179,7 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {
}

t.Run(testName, func(t *testing.T) {
cnt := 0
cnt.Store(0)
wg := sync.WaitGroup{}
wait := make(chan struct{})

Expand All @@ -189,7 +192,7 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {
// should not be cancelled by the tracker
require.NoError(t, ctx.Err())
case <-wait:
cnt++
cnt.Add(1)
case <-time.After(time.Second):
}
}
Expand Down Expand Up @@ -221,7 +224,7 @@ func TestIngesterQuerier_earlyExitOnQuorum(t *testing.T) {

err = testData.testFn(ingesterQuerier)
ingesterClient.AssertNumberOfCalls(t, testData.method, 3)
require.Equal(t, 2, cnt)
require.Equal(t, int32(2), cnt.Load())
if retErr {
require.ErrorContains(t, err, testData.method+" failed")
} else {
Expand Down
6 changes: 5 additions & 1 deletion pkg/querier/queryrange/split_by_interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,11 @@ func Test_ExitEarly(t *testing.T) {

res, err := split.Do(ctx, req)

require.Equal(t, int(req.Limit), callCt)
mtx.Lock()
count := callCt
mtx.Unlock()

require.Equal(t, int(req.Limit), count)
require.NoError(t, err)
require.Equal(t, expected, res)
}
Expand Down
Loading