Skip to content

Commit

Permalink
remove usage of rand.Seed() (#7343)
Browse files Browse the repository at this point in the history
  • Loading branch information
sluongng authored Aug 30, 2024
1 parent f1401af commit 5e242dc
Show file tree
Hide file tree
Showing 17 changed files with 0 additions and 51 deletions.
4 changes: 0 additions & 4 deletions enterprise/server/backends/authdb/authdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
)

func TestSessionInsertUpdateDeleteRead(t *testing.T) {
rand.Seed(time.Now().UnixNano())
ctx := context.Background()
env := setupEnv(t)
adb := env.GetAuthDB()
Expand Down Expand Up @@ -245,7 +244,6 @@ func TestBackfillUnencryptedKeys(t *testing.T) {
}

func TestGetAPIKeyGroupFromAPIKeyID(t *testing.T) {
rand.Seed(time.Now().UnixNano())
ctx := context.Background()
env := setupEnv(t)
adb := env.GetAuthDB()
Expand Down Expand Up @@ -320,7 +318,6 @@ func TestGetAPIKeys(t *testing.T) {
}

func TestGetAPIKeyGroup_UserOwnedKeys(t *testing.T) {
rand.Seed(time.Now().UnixNano())
ctx := context.Background()
env := setupEnv(t)
adb := env.GetAuthDB()
Expand Down Expand Up @@ -387,7 +384,6 @@ func TestGetAPIKeyGroup_UserOwnedKeys(t *testing.T) {
}

func TestLookupUserFromSubID(t *testing.T) {
rand.Seed(time.Now().UnixNano())
ctx := context.Background()
env := setupEnv(t)
adb := env.GetAuthDB()
Expand Down
2 changes: 0 additions & 2 deletions enterprise/server/backends/pebble_cache/pebble_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2390,8 +2390,6 @@ func createKey(t *testing.T, env environment.Env, keyID, groupID, groupKeyURI st
}

func getCrypterEnv(t *testing.T) (*testenv.TestEnv, string) {
rand.Seed(time.Now().UnixMicro())

kmsDir := testfs.MakeTempDir(t)
masterKeyURI := generateKMSKey(t, kmsDir, "masterKey")

Expand Down
2 changes: 0 additions & 2 deletions enterprise/server/crypter_service/crypter_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ func createKey(t *testing.T, env environment.Env, clock clockwork.Clock, keyID,
}

func getEnv(t *testing.T) (*testenv.TestEnv, *fakeKMS) {
mrand.Seed(time.Now().UnixMicro())

kms := newFakeKMS(t)

generateKMSKey(t, kms, "master")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func TestFirecracker_RemoteSnapshotSharing_ManualBenchmarking(t *testing.T) {
flags.Set(t, "app.log_level", "fatal")
log.Configure()

rand.Seed(time.Now().UnixNano())

var containersToCleanup []*firecracker.FirecrackerContainer
t.Cleanup(func() {
for _, vm := range containersToCleanup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sync"
"syscall"
"testing"
"time"

"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/copy_on_write"
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/copy_on_write/cow_cgo_testutil"
Expand All @@ -40,7 +39,6 @@ const (
)

func init() {
rand.Seed(time.Now().UnixNano())
// Ensure some memory is allocated for the shared LRU.
if err := resources.Configure(true /*=snapshotSharingEnabled*/); err != nil {
log.Fatalf("Failed to configure resources: %s", err)
Expand Down
4 changes: 0 additions & 4 deletions enterprise/server/remote_execution/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ func TestRunnerPool_Shutdown_RemovesPausedRunners(t *testing.T) {
}

func TestRunnerPool_Shutdown_RunnersReturnRetriableOrNilError(t *testing.T) {
seed := time.Now().UnixNano()
rand.Seed(seed)
t.Logf("Random seed: %d", seed)

env := newTestEnv(t)
ctx := withAuthenticatedUser(t, context.Background(), env, "US1")

Expand Down
4 changes: 0 additions & 4 deletions enterprise/server/scheduling/task_router/task_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package task_router_test
import (
"context"
"fmt"
"math/rand"
"testing"
"time"

"github.com/buildbuddy-io/buildbuddy/enterprise/server/scheduling/task_router"
"github.com/buildbuddy-io/buildbuddy/enterprise/server/testutil/enterprise_testenv"
Expand Down Expand Up @@ -573,8 +571,6 @@ func newTaskRouter(t *testing.T, env environment.Env) interfaces.TaskRouter {
}

func newTestEnv(t *testing.T) environment.Env {
rand.Seed(time.Now().UnixNano())

redisTarget := testredis.Start(t).Target
env := enterprise_testenv.GetCustomTestEnv(t, &enterprise_testenv.Options{
RedisTarget: redisTarget,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ func (r *Env) setupRootDirectoryWithTestCommandBinary(ctx context.Context) *repb
// The returned environment does not have any executors by default. Use the
// Add*Executor functions to add executors.
func NewRBETestEnv(t *testing.T) *Env {
seed := time.Now().UnixNano()
rand.Seed(seed)
log.Infof("Test seed: %d", seed)

redisTarget := testredis.Start(t).Target
envOpts := &enterprise_testenv.Options{RedisTarget: redisTarget}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ func TestAuthenticatedInvocation_CacheEnabled(t *testing.T) {
}

func TestAuthenticatedInvocation_PersonalAPIKey_CacheEnabled(t *testing.T) {
rand.Seed(time.Now().UnixNano())

wt := webtester.New(t)
target := buildbuddy_enterprise.SetupWebTarget(t)

Expand Down
2 changes: 0 additions & 2 deletions enterprise/server/util/dsingleflight/dsingleflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestDo(t *testing.T) {
c := New(rdb)
ctx := context.Background()

rand.Seed(time.Now().UnixNano())
key := fmt.Sprintf("key-%d", rand.Int())

wg, ctx := errgroup.WithContext(ctx)
Expand Down Expand Up @@ -70,7 +69,6 @@ func TestDoError(t *testing.T) {
c := New(rdb)
ctx := context.Background()

rand.Seed(time.Now().UnixNano())
key := fmt.Sprintf("key-%d", rand.Int())

wg, ctx := errgroup.WithContext(ctx)
Expand Down
2 changes: 0 additions & 2 deletions enterprise/tools/rbeperf/rbeperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,6 @@ func (c *ClientSource) GetByteStreamClient() bspb.ByteStreamClient {

func main() {
flag.Parse()
rand.Seed(time.Now().UnixNano())

if *verbose {
*log.LogLevel = "debug"
}
Expand Down
3 changes: 0 additions & 3 deletions enterprise/tools/vmstart/vmstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/container"
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/containers/firecracker"
Expand Down Expand Up @@ -164,8 +163,6 @@ func main() {
flagutil.SetValueForFlagName("debug_disable_firecracker_workspace_sync", true, nil, false)
}

rand.Seed(time.Now().Unix())

env := getToolEnv()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
1 change: 0 additions & 1 deletion server/remote_cache/scorecard/scorecard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func TestGetCacheScoreCard_GroupByActionOrderByDurationDesc(t *testing.T) {
}

func TestGetCacheScoreCard_GroupByTargetOrderByDuration(t *testing.T) {
rand.Seed(time.Now().UnixNano())
expectedResults := []*capb.ScoreCard_Result{}
// Set up results so that expected action IDs alternate within each target
// group, and so that durations across groups have some overlap.
Expand Down
5 changes: 0 additions & 5 deletions server/util/consistent_hash/consistent_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
const numVnodes = 100

func TestNodesetOrderIndependence(t *testing.T) {
rand.Seed(time.Now().UnixNano())
assert := assert.New(t)
ch := consistent_hash.NewConsistentHash(consistent_hash.CRC32, numVnodes)

Expand Down Expand Up @@ -57,7 +56,6 @@ func TestNodesetOrderIndependence(t *testing.T) {
}

func TestGetAllReplicas(t *testing.T) {
rand.Seed(time.Now().UnixNano())
assert := assert.New(t)
ch := consistent_hash.NewConsistentHash(consistent_hash.CRC32, numVnodes)

Expand All @@ -81,8 +79,6 @@ func TestGetAllReplicas(t *testing.T) {
}

func TestEvenLoadDistribution(t *testing.T) {
rand.Seed(time.Now().UnixNano())

rng := bufio.NewReader(rand.New(rand.NewSource(time.Now().UnixNano())))

// Record the frequency of each host returned by Get() across 1M random
Expand Down Expand Up @@ -123,7 +119,6 @@ func BenchmarkGetAllReplicas(b *testing.B) {
{Name: "SHA256/10000_vnodes", HashFunction: consistent_hash.SHA256, NumVnodes: 10000},
} {
b.Run(test.Name, func(b *testing.B) {
rand.Seed(time.Now().UnixNano())
assert := assert.New(b)
ch := consistent_hash.NewConsistentHash(test.HashFunction, test.NumVnodes)

Expand Down
4 changes: 0 additions & 4 deletions server/util/lockingbuffer/lockingbuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
)

func TestLockingBuffer_ReadWrite(t *testing.T) {
rand.Seed(int64(time.Now().UnixNano()))

buf := lockingbuffer.New()

writer := func(val string, writeCount int, done *bool, doneLock *sync.RWMutex) {
Expand Down Expand Up @@ -97,8 +95,6 @@ func charCount(s string, c byte) int {
}

func TestLockingBuffer_ReadAll(t *testing.T) {
rand.Seed(int64(time.Now().UnixNano()))

buf := lockingbuffer.New()

writer := func(val string, writeCount int, done *bool, doneLock *sync.RWMutex) {
Expand Down
5 changes: 0 additions & 5 deletions server/util/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package random
import (
"io"
"sync"
"time"

"github.com/buildbuddy-io/buildbuddy/server/util/log"

Expand All @@ -22,10 +21,6 @@ func init() {
}

func RandUint64() uint64 {
once.Do(func() {
mrand.Seed(time.Now().UnixNano())
log.Debugf("Seeded random with current time!")
})
return mrand.Uint64()
}

Expand Down
3 changes: 0 additions & 3 deletions tools/probers/bazelrbe/bazelrbe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/buildbuddy-io/buildbuddy/server/util/bazel"
"github.com/buildbuddy-io/buildbuddy/server/util/log"
Expand Down Expand Up @@ -141,8 +140,6 @@ func main() {
log.Fatalf("--bazel_binary is required")
}

rand.Seed(time.Now().UnixNano())

err := runProbe()
if err != nil {
log.Fatalf("Probe failure: %s", err)
Expand Down

0 comments on commit 5e242dc

Please sign in to comment.