Skip to content

Commit

Permalink
fix: data race in ingester test (#15465)
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- authored Dec 18, 2024
1 parent 4d71ca3 commit 04f621e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"testing"
"time"

"go.uber.org/atomic"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/backoff"
Expand Down Expand Up @@ -1498,7 +1500,7 @@ func jsonLine(ts int64, i int) string {

type readRingMock struct {
replicationSet ring.ReplicationSet
getAllHealthyCallsCount int
getAllHealthyCallsCount atomic.Int32
tokenRangesByIngester map[string]ring.TokenRanges
}

Expand Down Expand Up @@ -1538,7 +1540,7 @@ func (r *readRingMock) BatchGet(_ []uint32, _ ring.Operation) ([]ring.Replicatio
}

func (r *readRingMock) GetAllHealthy(_ ring.Operation) (ring.ReplicationSet, error) {
r.getAllHealthyCallsCount++
r.getAllHealthyCallsCount.Add(1)
return r.replicationSet, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/ingester/recalculate_owned_streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func Test_recalculateOwnedStreams_newRecalculateOwnedStreamsIngester(t *testing.
}, 0)
strategy := newOwnedStreamsIngesterStrategy("test", mockRing, log.NewNopLogger())
service := newRecalculateOwnedStreamsSvc(mockInstancesSupplier.get, strategy, 50*time.Millisecond, log.NewNopLogger())
require.Equal(t, 0, mockRing.getAllHealthyCallsCount, "ring must be called only after service's start up")
require.Equal(t, int32(0), mockRing.getAllHealthyCallsCount.Load(), "ring must be called only after service's start up")
ctx := context.Background()
require.NoError(t, service.StartAsync(ctx))
require.NoError(t, service.AwaitRunning(ctx))
require.Eventually(t, func() bool {
return mockRing.getAllHealthyCallsCount >= 2
return mockRing.getAllHealthyCallsCount.Load() >= 2
}, 1*time.Second, 50*time.Millisecond, "expected at least two runs of the iteration")
}

Expand Down

0 comments on commit 04f621e

Please sign in to comment.