Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Nov 17, 2023
1 parent 1f5dfae commit 20b0e4a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
5 changes: 5 additions & 0 deletions pkg/shardedmutex/shardedmutex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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{}
Expand Down Expand Up @@ -60,6 +64,7 @@ func TestLockingSameShardsBlocks(t *testing.T) {
}

func TestShardedByString(t *testing.T) {
testflags.UnitTest(t)
shards := 16
sm := NewFor(maphash.String, shards)

Expand Down
2 changes: 2 additions & 0 deletions pkg/util/merge_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tools/gengen/util/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 13 additions & 5 deletions venus-shared/testutil/value_provider_primitive.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package testutil

import (
crand "crypto/rand"
"encoding/hex"
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 0 additions & 7 deletions venus-shared/testutil/value_provider_primitive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"encoding/hex"
"math/rand"
"reflect"
"testing"
"time"
Expand All @@ -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)

Expand Down

0 comments on commit 20b0e4a

Please sign in to comment.