Skip to content

Commit d92e3be

Browse files
Merge pull request #39 from zenon-network/dep/rand-seed
[dep] Use Rand type instead of deprecated rand.Seed
2 parents 3f803d0 + cade01b commit d92e3be

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

common/db/memdb_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010

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

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

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

106107
for i := 0; i < numThreads; i += 1 {
107108
dbs = append(dbs, db)
108109
currentInputs := make([][2][]byte, numInserts)
109110
for i := 0; i < numInserts; i += 1 {
110-
currentInputs[i][0] = common.Uint64ToBytes(rand.Uint64())
111-
currentInputs[i][1] = common.Uint64ToBytes(rand.Uint64())
111+
currentInputs[i][0] = common.Uint64ToBytes(r.Uint64())
112+
currentInputs[i][1] = common.Uint64ToBytes(r.Uint64())
112113
}
113114
inputs = append(inputs, currentInputs)
114115
}

common/db/versioned_db_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func newMockTransaction(seed int64, db DB) *mockTransaction {
5353
height: frontier.Height + 1,
5454
}
5555

56-
rand.Seed(seed)
57-
stressTestConcurrentUse(nil, db, 5, 1)
56+
r := rand.New(rand.NewSource(seed))
57+
stressTestConcurrentUse(nil, db, 5, 1, r)
5858

5959
changes, _ := db.Changes()
6060
ab.changesHash = PatchHash(changes)

0 commit comments

Comments
 (0)