diff --git a/test/helpers/name.go b/test/helpers/name.go index 4da8e4dc84..18a93f2518 100644 --- a/test/helpers/name.go +++ b/test/helpers/name.go @@ -19,6 +19,7 @@ package helpers import ( "math/rand" "strings" + "sync" "time" "unicode" ) @@ -32,7 +33,10 @@ const ( testNamePrefix = "Test" ) -var nameRand *rand.Rand +var ( + nameRand *rand.Rand + nameMu sync.Mutex +) func init() { // Properly seed the random number generator so RandomString() is actually random. @@ -75,9 +79,11 @@ func AppendRandomString(prefix string) string { // RandomString will generate a random string. func RandomString() string { suffix := make([]byte, randSuffixLen) + nameMu.Lock() for i := range suffix { suffix[i] = letterBytes[nameRand.Intn(len(letterBytes))] } + nameMu.Unlock() return string(suffix) }