Skip to content

Commit

Permalink
[dep] Use Rand type instead of deprecated rand.Seed
Browse files Browse the repository at this point in the history
Determinstic random generator should not be set by rand.Seed
https://pkg.go.dev/math/rand#Seed
golang/go#56319
  • Loading branch information
georgezgeorgez committed Sep 28, 2023
1 parent 68a8f34 commit cade01b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions common/db/memdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

func TestStressMemDB(t *testing.T) {
simpleMemDBOperations(t, NewMemDB())
stressTestConcurrentUse(t, NewMemDB(), 1e5, 20)
stressTestConcurrentUse(t, NewMemDB().Subset([]byte{10, 11, 12, 13}), 1e5, 10)
r := rand.New(rand.NewSource(rand.Int63()))
stressTestConcurrentUse(t, NewMemDB(), 1e5, 20, r)
stressTestConcurrentUse(t, NewMemDB().Subset([]byte{10, 11, 12, 13}), 1e5, 10, r)
}

func TestChanges(t *testing.T) {
Expand Down Expand Up @@ -99,16 +100,16 @@ func simpleMemDBOperations(t *testing.T, db DB) {
common.FailIfErr(t, db.Delete([]byte{1, 2, 3, 4}))
}

func stressTestConcurrentUse(t *testing.T, db DB, numInserts int, numThreads int) {
func stressTestConcurrentUse(t *testing.T, db DB, numInserts int, numThreads int, r *rand.Rand) {
inputs := make([][][2][]byte, 0, numThreads)
dbs := make([]DB, 0, numThreads)

for i := 0; i < numThreads; i += 1 {
dbs = append(dbs, db)
currentInputs := make([][2][]byte, numInserts)
for i := 0; i < numInserts; i += 1 {
currentInputs[i][0] = common.Uint64ToBytes(rand.Uint64())
currentInputs[i][1] = common.Uint64ToBytes(rand.Uint64())
currentInputs[i][0] = common.Uint64ToBytes(r.Uint64())
currentInputs[i][1] = common.Uint64ToBytes(r.Uint64())
}
inputs = append(inputs, currentInputs)
}
Expand Down
4 changes: 2 additions & 2 deletions common/db/versioned_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func newMockTransaction(seed int64, db DB) *mockTransaction {
height: frontier.Height + 1,
}

rand.Seed(seed)
stressTestConcurrentUse(nil, db, 5, 1)
r := rand.New(rand.NewSource(seed))
stressTestConcurrentUse(nil, db, 5, 1, r)

changes, _ := db.Changes()
ab.changesHash = PatchHash(changes)
Expand Down

0 comments on commit cade01b

Please sign in to comment.