From 7030429958ac3ed6c762f1db241eddc64688d019 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 23 Jan 2023 19:43:18 -0800 Subject: [PATCH] lib/mergeset: fix data race in BenchmarkInmemoryBlockMarshal --- lib/mergeset/encoding_timing_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/mergeset/encoding_timing_test.go b/lib/mergeset/encoding_timing_test.go index 2955cc3f5..1a8ed4d88 100644 --- a/lib/mergeset/encoding_timing_test.go +++ b/lib/mergeset/encoding_timing_test.go @@ -50,19 +50,20 @@ func BenchmarkInmemoryBlockMarshal(b *testing.B) { func benchmarkInmemoryBlockMarshal(b *testing.B, prefix string) { const itemsCount = 500 - var ibSrc inmemoryBlock - for i := 0; i < itemsCount; i++ { - item := []byte(fmt.Sprintf("%s%d", prefix, i)) - if !ibSrc.Add(item) { - b.Fatalf("cannot add more than %d items", i) - } - } - sort.Sort(&ibSrc) b.ResetTimer() b.SetBytes(int64(itemsCount * len(prefix))) b.ReportAllocs() b.RunParallel(func(pb *testing.PB) { + var ibSrc inmemoryBlock + for i := 0; i < itemsCount; i++ { + item := []byte(fmt.Sprintf("%s%d", prefix, i)) + if !ibSrc.Add(item) { + b.Fatalf("cannot add more than %d items", i) + } + } + sort.Sort(&ibSrc) + var sb storageBlock var firstItem, commonPrefix []byte var n uint32