diff --git a/pkg/shardedmutex/shardedmutex_test.go b/pkg/shardedmutex/shardedmutex_test.go index a7d5f7d1df..2c6cf2eaa0 100644 --- a/pkg/shardedmutex/shardedmutex_test.go +++ b/pkg/shardedmutex/shardedmutex_test.go @@ -8,9 +8,12 @@ import ( "sync/atomic" "testing" "time" + + "github.com/filecoin-project/venus/pkg/testhelpers/testflags" ) func TestLockingDifferentShardsDoesNotBlock(t *testing.T) { + testflags.UnitTest(t) shards := 16 sm := New(shards) done := make(chan struct{}) @@ -29,6 +32,7 @@ func TestLockingDifferentShardsDoesNotBlock(t *testing.T) { close(done) } func TestLockingSameShardsBlocks(t *testing.T) { + testflags.UnitTest(t) shards := 16 sm := New(shards) wg := sync.WaitGroup{} @@ -60,6 +64,7 @@ func TestLockingSameShardsBlocks(t *testing.T) { } func TestShardedByString(t *testing.T) { + testflags.UnitTest(t) shards := 16 sm := NewFor(maphash.String, shards) diff --git a/pkg/util/merge_peer_test.go b/pkg/util/merge_peer_test.go index 88bdf1cc84..13c2a201ac 100644 --- a/pkg/util/merge_peer_test.go +++ b/pkg/util/merge_peer_test.go @@ -3,10 +3,12 @@ package util import ( "testing" + "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "github.com/stretchr/testify/assert" ) func TestMergePeers(t *testing.T) { + testflags.UnitTest(t) t1 := MergePeers([]string{}, []string{"a"}) assert.Equal(t, []string{"a"}, t1) diff --git a/tools/gengen/util/generator.go b/tools/gengen/util/generator.go index e96f2f3dcd..2d04bd5456 100644 --- a/tools/gengen/util/generator.go +++ b/tools/gengen/util/generator.go @@ -119,7 +119,7 @@ func (g *GenesisGenerator) Init(cfg *GenesisCfg) error { } keys = append(keys, cfg.ImportKeys...) g.keys = keys - vrKey, err := key.NewSecpKeyFromSeed(g.pnrg) + vrKey, err := key.NewBLSKeyFromSeed(g.pnrg) if err != nil { return err } diff --git a/venus-shared/testutil/value_provider_primitive.go b/venus-shared/testutil/value_provider_primitive.go index 00366a140c..530d23f3b6 100644 --- a/venus-shared/testutil/value_provider_primitive.go +++ b/venus-shared/testutil/value_provider_primitive.go @@ -1,10 +1,10 @@ package testutil import ( - crand "crypto/rand" "encoding/hex" "math/rand" "testing" + "time" "github.com/stretchr/testify/require" ) @@ -20,7 +20,7 @@ const ( defaultBytesFixedSize = 16 ) -func IntProvider(t *testing.T) int { return rand.Int() } +func IntProvider(t *testing.T) int { return r.Int() } func IntRangedProvider(min, max int) func(*testing.T) int { return func(t *testing.T) int { @@ -29,14 +29,22 @@ func IntRangedProvider(min, max int) func(*testing.T) int { t.Fatalf("invalid range [%d, %d)", min, max) } - return min + rand.Intn(gap) + return min + r.Intn(gap) } } +var r = rand.New(rand.NewSource(time.Now().UnixNano())) + +func getRand() *rand.Rand { + seed := time.Now().UnixNano() + r = rand.New(rand.NewSource(seed)) + return rand.New(rand.NewSource(seed)) +} + func BytesFixedProvider(size int) func(*testing.T) []byte { return func(t *testing.T) []byte { b := make([]byte, size) - _, err := crand.Read(b[:]) + _, err := r.Read(b[:]) require.NoError(t, err) return b } @@ -45,7 +53,7 @@ func BytesFixedProvider(size int) func(*testing.T) []byte { func BytesAtMostProvider(size int) func(*testing.T) []byte { return func(t *testing.T) []byte { b := make([]byte, rand.Intn(size)) - _, err := crand.Read(b[:]) + _, err := r.Read(b[:]) require.NoError(t, err) return b } diff --git a/venus-shared/testutil/value_provider_primitive_test.go b/venus-shared/testutil/value_provider_primitive_test.go index 849b5069cf..8efaedcc7a 100644 --- a/venus-shared/testutil/value_provider_primitive_test.go +++ b/venus-shared/testutil/value_provider_primitive_test.go @@ -2,7 +2,6 @@ package testutil import ( "encoding/hex" - "math/rand" "reflect" "testing" "time" @@ -11,12 +10,6 @@ import ( "github.com/stretchr/testify/require" ) -func getRand() *rand.Rand { - seed := time.Now().UnixNano() - rand.New(rand.NewSource(seed)) - return rand.New(rand.NewSource(seed)) -} - func TestDefaultBytes(t *testing.T) { tf.UnitTest(t)