Skip to content

Commit

Permalink
test: 2 data race fixes (grafana#12584)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul1r authored and rhnasc committed Apr 12, 2024
1 parent dd31a5f commit d0147c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/storage/chunk/cache/embeddedcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func TestEmbeddedCacheExpiry(t *testing.T) {
_, ok = c.Get(ctx, key1)
require.False(t, ok)

c.lock.RLock()
assert.Equal(t, float64(4), testutil.ToFloat64(c.entriesAddedNew))
assert.Equal(t, float64(0), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(expiredReason)))
assert.Equal(t, float64(1), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(fullReason)))
Expand All @@ -211,12 +212,14 @@ func TestEmbeddedCacheExpiry(t *testing.T) {
assert.Equal(t, float64(c.lru.Len()), testutil.ToFloat64(c.entriesCurrent))
assert.Equal(t, float64(memorySz), testutil.ToFloat64(c.memoryBytes))
assert.Equal(t, int64(1), removedEntriesCount.Load(), "on removal callback had to be called for key1")
c.lock.RUnlock()

// Expire the item.
time.Sleep(2 * cfg.TTL)
_, ok = c.Get(ctx, key4)
require.False(t, ok)

c.lock.RLock()
assert.Equal(t, float64(4), testutil.ToFloat64(c.entriesAddedNew))
assert.Equal(t, float64(3), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(expiredReason)))
assert.Equal(t, float64(1), testutil.ToFloat64(c.entriesEvicted.WithLabelValues(fullReason)))
Expand All @@ -225,6 +228,7 @@ func TestEmbeddedCacheExpiry(t *testing.T) {
assert.Equal(t, float64(c.lru.Len()), testutil.ToFloat64(c.entriesCurrent))
assert.Equal(t, float64(memorySz), testutil.ToFloat64(c.memoryBytes))
assert.Equal(t, int64(4), removedEntriesCount.Load(), "on removal callback had to be called for all 3 expired entries")
c.lock.RUnlock()

c.Stop()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ func NewTableManager(cfg Config, indexShipper Shipper, tableRange config.TableRa
}

tm.tables = tables
// Increment the WaitGroup counter here before starting the goroutine
tm.wg.Add(1)
go tm.loop()
return &tm, nil
}

func (tm *TableManager) loop() {
tm.wg.Add(1)
defer tm.wg.Done()

tm.handoverIndexesToShipper(false)
Expand Down

0 comments on commit d0147c4

Please sign in to comment.