tsdb tests: avoid capture-by-reference in goroutines

Only one version of the variable is captured; this is a source of race conditions.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-11-27 15:13:01 +00:00
parent 54cf0d6879
commit f4fbe47254
2 changed files with 6 additions and 5 deletions

View file

@ -1575,12 +1575,13 @@ func TestHeadCompactionWithHistograms(t *testing.T) {
func TestSparseHistogramSpaceSavings(t *testing.T) {
t.Skip()
cases := []struct {
type testcase struct {
numSeriesPerSchema int
numBuckets int
numSpans int
gapBetweenSpans int
}{
}
cases := []testcase{
{1, 15, 1, 0},
{1, 50, 1, 0},
{1, 100, 1, 0},
@ -1692,7 +1693,7 @@ func TestSparseHistogramSpaceSavings(t *testing.T) {
}()
wg.Add(1)
go func() {
go func(c testcase) {
defer wg.Done()
// Ingest histograms the old way.
@ -1740,7 +1741,7 @@ func TestSparseHistogramSpaceSavings(t *testing.T) {
oldULIDs, err = compactor.Write(oldHead.opts.ChunkDirRoot, oldHead, mint, maxt, nil)
require.NoError(t, err)
require.Len(t, oldULIDs, 1)
}()
}(c)
wg.Wait()

View file

@ -694,9 +694,9 @@ func (h *Head) loadWBL(r *wlog.Reader, syms *labels.SymbolTable, multiRef map[ch
go func() {
defer close(decodedCh)
var err error
dec := record.NewDecoder(syms)
for r.Next() {
var err error
rec := r.Record()
switch dec.Type(rec) {
case record.Samples: