diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index fcb841efb72..ef064e467d6 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -57,6 +57,14 @@ var ( emptyResponse = &cortexpb.WriteResponse{} ) +var ( + randomStrings = []string{} +) + +func init() { + randomStrings = util.GenerateRandomStrings() +} + func TestConfig_Validate(t *testing.T) { t.Parallel() tests := map[string]struct { @@ -2466,8 +2474,8 @@ func prepare(tb testing.TB, cfg prepConfig) ([]*Distributor, []*mockIngester, [] // Strings to be used for get labels values/Names var unusedStrings []string if cfg.lblValuesPerIngester > 0 { - unusedStrings = make([]string, min(len(util.RandomStrings), cfg.numIngesters*cfg.lblValuesPerIngester)) - copy(unusedStrings, util.RandomStrings) + unusedStrings = make([]string, min(len(randomStrings), cfg.numIngesters*cfg.lblValuesPerIngester)) + copy(unusedStrings, randomStrings) } s := &prepState{ unusedStrings: unusedStrings, diff --git a/pkg/util/strings_test.go b/pkg/util/strings_test.go index 75496c7c460..de4cc28092e 100644 --- a/pkg/util/strings_test.go +++ b/pkg/util/strings_test.go @@ -48,6 +48,7 @@ func BenchmarkMergeSlicesParallel(b *testing.B) { }, } + randomStrings := GenerateRandomStrings() type ParallelismType int const ( @@ -58,9 +59,9 @@ func BenchmarkMergeSlicesParallel(b *testing.B) { for _, tc := range testCases { input := make([][]string, tc.inputSize) - unusedStrings := make([]string, min(len(RandomStrings), tc.inputSize*tc.stringsPerInput)) + unusedStrings := make([]string, min(len(randomStrings), tc.inputSize*tc.stringsPerInput)) usedStrings := make([]string, 0, len(unusedStrings)) - copy(unusedStrings, RandomStrings) + copy(unusedStrings, randomStrings) for i := 0; i < tc.inputSize; i++ { stringsToBeReused := make([]string, len(usedStrings)) diff --git a/pkg/util/test_util.go b/pkg/util/test_util.go index 4f9c65f010a..7cc95abe2fb 100644 --- a/pkg/util/test_util.go +++ b/pkg/util/test_util.go @@ -5,12 +5,9 @@ import ( "strings" ) -var ( - randomChar = "0123456789abcdef" - RandomStrings = []string{} -) - -func init() { +func GenerateRandomStrings() []string { + randomChar := "0123456789abcdef" + randomStrings := make([]string, 0, 1000000) sb := strings.Builder{} for i := 0; i < 1000000; i++ { sb.Reset() @@ -18,6 +15,7 @@ func init() { for j := 0; j < 14; j++ { sb.WriteByte(randomChar[rand.Int()%len(randomChar)]) } - RandomStrings = append(RandomStrings, sb.String()) + randomStrings = append(randomStrings, sb.String()) } + return randomStrings }