Compare commits

..

No commits in common. "023b90342cf9448cd9867a28dae04d7e90d4450c" and "5b7e4a51b76313a7502c65f048f4f695788a3039" have entirely different histories.

11 changed files with 28 additions and 36 deletions

View file

@ -2,8 +2,8 @@ package blobovnicza
import ( import (
"context" "context"
"crypto/rand"
"errors" "errors"
"math/rand"
"os" "os"
"testing" "testing"
@ -54,6 +54,8 @@ func testGet(t *testing.T, blz *Blobovnicza, addr oid.Address, expObj []byte, as
} }
func TestBlobovnicza(t *testing.T) { func TestBlobovnicza(t *testing.T) {
rand.Seed(1024)
p := "./test_blz" p := "./test_blz"
sizeLim := uint64(256 * 1 << 10) // 256KB sizeLim := uint64(256 * 1 << 10) // 256KB

View file

@ -2,8 +2,7 @@ package blobstortest
import ( import (
"context" "context"
"crypto/rand" "math/rand"
mrand "math/rand"
"testing" "testing"
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
@ -54,9 +53,8 @@ func TestInfo(t *testing.T, cons Constructor, expectedType string, expectedPath
func prepare(t *testing.T, count int, s common.Storage, min, max uint64) []objectDesc { func prepare(t *testing.T, count int, s common.Storage, min, max uint64) []objectDesc {
objects := make([]objectDesc, count) objects := make([]objectDesc, count)
r := mrand.New(mrand.NewSource(0))
for i := range objects { for i := range objects {
objects[i].obj = NewObject(min + uint64(r.Intn(int(max-min+1)))) // not too large objects[i].obj = NewObject(min + uint64(rand.Intn(int(max-min+1)))) // not too large
objects[i].addr = objectCore.AddressOf(objects[i].obj) objects[i].addr = objectCore.AddressOf(objects[i].obj)
raw, err := objects[i].obj.Marshal() raw, err := objects[i].obj.Marshal()

View file

@ -1,11 +1,9 @@
package meta package meta
import ( import (
"crypto/rand"
"math" "math"
mrand "math/rand" "math/rand"
"testing" "testing"
"time"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -41,10 +39,9 @@ func Test_decodeList(t *testing.T) {
require.Error(t, err) require.Error(t, err)
}) })
t.Run("random", func(t *testing.T) { t.Run("random", func(t *testing.T) {
r := mrand.New(mrand.NewSource(time.Now().Unix()))
expected := make([][]byte, 20) expected := make([][]byte, 20)
for i := range expected { for i := range expected {
expected[i] = make([]byte, r.Uint32()%10) expected[i] = make([]byte, rand.Uint32()%10)
rand.Read(expected[i]) rand.Read(expected[i])
} }

View file

@ -2,14 +2,12 @@ package pilorama
import ( import (
"context" "context"
"crypto/rand"
"fmt" "fmt"
mrand "math/rand" "math/rand"
"path/filepath" "path/filepath"
"strconv" "strconv"
"sync" "sync"
"testing" "testing"
"time"
cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" cidSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
@ -769,10 +767,9 @@ func prepareRandomTree(nodeCount, opCount int) []Move {
rand.Read(ops[i].Meta.Items[1].Value) rand.Read(ops[i].Meta.Items[1].Value)
} }
r := mrand.New(mrand.NewSource(time.Now().Unix()))
for i := nodeCount; i < len(ops); i++ { for i := nodeCount; i < len(ops); i++ {
ops[i] = Move{ ops[i] = Move{
Parent: r.Uint64() % uint64(nodeCount+12), Parent: rand.Uint64() % uint64(nodeCount+12),
Meta: Meta{ Meta: Meta{
Time: Timestamp(i + nodeCount), Time: Timestamp(i + nodeCount),
Items: []KeyValue{ Items: []KeyValue{
@ -780,9 +777,9 @@ func prepareRandomTree(nodeCount, opCount int) []Move {
{Value: make([]byte, 10)}, {Value: make([]byte, 10)},
}, },
}, },
Child: r.Uint64() % uint64(nodeCount+10), Child: rand.Uint64() % uint64(nodeCount+10),
} }
if r.Uint32()%5 == 0 { if rand.Uint32()%5 == 0 {
ops[i].Parent = TrashID ops[i].Parent = TrashID
} }
rand.Read(ops[i].Meta.Items[1].Value) rand.Read(ops[i].Meta.Items[1].Value)
@ -816,7 +813,7 @@ func compareForests(t *testing.T, expected, actual Forest, cid cidSDK.ID, treeID
} }
func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _ ...Option) Forest, batchSize, opCount, iterCount int) { func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _ ...Option) Forest, batchSize, opCount, iterCount int) {
r := mrand.New(mrand.NewSource(42)) rand.Seed(42)
const nodeCount = 5 const nodeCount = 5
@ -832,7 +829,7 @@ func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _
for i := 0; i < iterCount; i++ { for i := 0; i < iterCount; i++ {
// Shuffle random operations, leave initialization in place. // Shuffle random operations, leave initialization in place.
r.Shuffle(len(ops), func(i, j int) { ops[i], ops[j] = ops[j], ops[i] }) rand.Shuffle(len(ops), func(i, j int) { ops[i], ops[j] = ops[j], ops[i] })
actual := constructor(t, WithMaxBatchSize(batchSize)) actual := constructor(t, WithMaxBatchSize(batchSize))
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
@ -858,7 +855,7 @@ func testForestTreeParallelApply(t *testing.T, constructor func(t testing.TB, _
} }
func testForestTreeApplyRandom(t *testing.T, constructor func(t testing.TB, _ ...Option) Forest) { func testForestTreeApplyRandom(t *testing.T, constructor func(t testing.TB, _ ...Option) Forest) {
r := mrand.New(mrand.NewSource(42)) rand.Seed(42)
const ( const (
nodeCount = 5 nodeCount = 5
@ -878,7 +875,7 @@ func testForestTreeApplyRandom(t *testing.T, constructor func(t testing.TB, _ ..
const iterCount = 200 const iterCount = 200
for i := 0; i < iterCount; i++ { for i := 0; i < iterCount; i++ {
// Shuffle random operations, leave initialization in place. // Shuffle random operations, leave initialization in place.
r.Shuffle(len(ops), func(i, j int) { ops[i], ops[j] = ops[j], ops[i] }) rand.Shuffle(len(ops), func(i, j int) { ops[i], ops[j] = ops[j], ops[i] })
actual := constructor(t) actual := constructor(t)
for i := range ops { for i := range ops {
@ -900,18 +897,17 @@ func BenchmarkApplySequential(b *testing.B) {
b.Run(providers[i].name, func(b *testing.B) { b.Run(providers[i].name, func(b *testing.B) {
for _, bs := range batchSizes { for _, bs := range batchSizes {
b.Run("batchsize="+strconv.Itoa(bs), func(b *testing.B) { b.Run("batchsize="+strconv.Itoa(bs), func(b *testing.B) {
r := mrand.New(mrand.NewSource(time.Now().Unix()))
s := providers[i].construct(b, WithMaxBatchSize(bs)) s := providers[i].construct(b, WithMaxBatchSize(bs))
benchmarkApply(b, s, func(opCount int) []Move { benchmarkApply(b, s, func(opCount int) []Move {
ops := make([]Move, opCount) ops := make([]Move, opCount)
for i := range ops { for i := range ops {
ops[i] = Move{ ops[i] = Move{
Parent: uint64(r.Intn(benchNodeCount)), Parent: uint64(rand.Intn(benchNodeCount)),
Meta: Meta{ Meta: Meta{
Time: Timestamp(i), Time: Timestamp(i),
Items: []KeyValue{{Value: []byte{0, 1, 2, 3, 4}}}, Items: []KeyValue{{Value: []byte{0, 1, 2, 3, 4}}},
}, },
Child: uint64(r.Intn(benchNodeCount)), Child: uint64(rand.Intn(benchNodeCount)),
} }
} }
return ops return ops
@ -934,18 +930,17 @@ func BenchmarkApplyReorderLast(b *testing.B) {
b.Run(providers[i].name, func(b *testing.B) { b.Run(providers[i].name, func(b *testing.B) {
for _, bs := range batchSizes { for _, bs := range batchSizes {
b.Run("batchsize="+strconv.Itoa(bs), func(b *testing.B) { b.Run("batchsize="+strconv.Itoa(bs), func(b *testing.B) {
r := mrand.New(mrand.NewSource(time.Now().Unix()))
s := providers[i].construct(b, WithMaxBatchSize(bs)) s := providers[i].construct(b, WithMaxBatchSize(bs))
benchmarkApply(b, s, func(opCount int) []Move { benchmarkApply(b, s, func(opCount int) []Move {
ops := make([]Move, opCount) ops := make([]Move, opCount)
for i := range ops { for i := range ops {
ops[i] = Move{ ops[i] = Move{
Parent: uint64(r.Intn(benchNodeCount)), Parent: uint64(rand.Intn(benchNodeCount)),
Meta: Meta{ Meta: Meta{
Time: Timestamp(i), Time: Timestamp(i),
Items: []KeyValue{{Value: []byte{0, 1, 2, 3, 4}}}, Items: []KeyValue{{Value: []byte{0, 1, 2, 3, 4}}},
}, },
Child: uint64(r.Intn(benchNodeCount)), Child: uint64(rand.Intn(benchNodeCount)),
} }
if i != 0 && i%blockSize == 0 { if i != 0 && i%blockSize == 0 {
for j := 0; j < blockSize/2; j++ { for j := 0; j < blockSize/2; j++ {
@ -962,6 +957,8 @@ func BenchmarkApplyReorderLast(b *testing.B) {
} }
func benchmarkApply(b *testing.B, s Forest, genFunc func(int) []Move) { func benchmarkApply(b *testing.B, s Forest, genFunc func(int) []Move) {
rand.Seed(42)
ops := genFunc(b.N) ops := genFunc(b.N)
cid := cidtest.ID() cid := cidtest.ID()
treeID := "version" treeID := "version"

View file

@ -1,7 +1,7 @@
package pilorama package pilorama
import ( import (
"crypto/rand" "math/rand"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"

View file

@ -2,7 +2,7 @@ package shard_test
import ( import (
"context" "context"
"crypto/rand" "math/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"

View file

@ -1,7 +1,7 @@
package util_test package util_test
import ( import (
"crypto/rand" "math/rand"
"testing" "testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util"

View file

@ -5,7 +5,6 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"github.com/dgraph-io/badger/v4" "github.com/dgraph-io/badger/v4"
badgeroptions "github.com/dgraph-io/badger/v4/options"
) )
// OpenDB opens a badger instance for write-cache. Opens in read-only mode if ro is true. // OpenDB opens a badger instance for write-cache. Opens in read-only mode if ro is true.
@ -13,7 +12,6 @@ func OpenDB(p string, ro bool, l *logger.Logger) (*badger.DB, error) {
return badger.Open(badger.DefaultOptions(p). return badger.Open(badger.DefaultOptions(p).
WithReadOnly(ro). WithReadOnly(ro).
WithSyncWrites(true). WithSyncWrites(true).
WithCompression(badgeroptions.None).
WithLoggingLevel(badger.ERROR). WithLoggingLevel(badger.ERROR).
WithLogger(badgerLoggerWrapper{l})) WithLogger(badgerLoggerWrapper{l}))
} }

View file

@ -9,11 +9,11 @@ import (
) )
func TestInitEndpoints(t *testing.T) { func TestInitEndpoints(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano())) rand.Seed(time.Now().UnixNano())
ee := make([]Endpoint, 100) ee := make([]Endpoint, 100)
for i := range ee { for i := range ee {
ee[i].Priority = r.Int() ee[i].Priority = rand.Int()
} }
var eeInternal endpoints var eeInternal endpoints

View file

@ -1,8 +1,8 @@
package netmap package netmap
import ( import (
"crypto/rand"
"math/big" "math/big"
"math/rand"
"strconv" "strconv"
"testing" "testing"