From 82669389b4f2693c7727fab46d308f332a0eca2c Mon Sep 17 00:00:00 2001 From: tom <69969590+simlecode@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:17:23 +0800 Subject: [PATCH] Merge pull request #6224 from filecoin-project/chore/update-go-version chore: ci: update go versin to v1.20 --- .circleci/config.yml | 2 +- .github/workflows/baisc_checks.yml | 4 ++-- .github/workflows/common_build_upload.yml | 4 ++-- .github/workflows/common_go.yml | 4 ++-- .github/workflows/test.yml | 2 +- pkg/messagepool/block_proba_test.go | 4 ++-- pkg/repo/fskeystore/fskeystore_test.go | 2 +- pkg/shardedmutex/shardedmutex_test.go | 5 +++++ pkg/util/fr32/fr32_test.go | 11 ++++++---- pkg/util/merge_peer_test.go | 2 ++ tools/gengen/util/generator.go | 2 +- .../testutil/value_provider_primitive.go | 21 +++++++++++++++---- .../testutil/value_provider_primitive_test.go | 7 ------- 13 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e9d286fc2f..def54fef46 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -72,7 +72,7 @@ commands: executors: golang: docker: - - image: cimg/go:1.19.10 + - image: cimg/go:1.20.11 jobs: test_all: diff --git a/.github/workflows/baisc_checks.yml b/.github/workflows/baisc_checks.yml index 5c91518780..90940693e5 100644 --- a/.github/workflows/baisc_checks.yml +++ b/.github/workflows/baisc_checks.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: '1.20' cache: true - name: install deps @@ -35,7 +35,7 @@ jobs: - name: Lint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.0 golangci-lint run --timeout 10m - name: Compatible all diff --git a/.github/workflows/common_build_upload.yml b/.github/workflows/common_build_upload.yml index 5d8ff3d733..142cf135e7 100644 --- a/.github/workflows/common_build_upload.yml +++ b/.github/workflows/common_build_upload.yml @@ -108,7 +108,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: '1.20' cache: true - name: install deps @@ -247,7 +247,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: '1.20' cache: true - name: install more deps diff --git a/.github/workflows/common_go.yml b/.github/workflows/common_go.yml index 61951b92c0..6b37e1d8d4 100644 --- a/.github/workflows/common_go.yml +++ b/.github/workflows/common_go.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: '1.20' cache: true - name: vars @@ -51,7 +51,7 @@ jobs: - name: Lint run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.0 golangci-lint run --timeout 10m - name: Detect changes diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ee49a3103..3a955adfee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: '1.20' cache: true - name: install deps diff --git a/pkg/messagepool/block_proba_test.go b/pkg/messagepool/block_proba_test.go index 1e0bac14b8..c341c661a3 100644 --- a/pkg/messagepool/block_proba_test.go +++ b/pkg/messagepool/block_proba_test.go @@ -26,12 +26,12 @@ func TestBlockProbability(t *testing.T) { func TestWinnerProba(t *testing.T) { tf.UnitTest(t) - rand.Seed(time.Now().UnixNano()) + r := rand.New(rand.NewSource(time.Now().UnixNano())) const N = 1000000 winnerProba := noWinnersProb() sum := 0 for i := 0; i < N; i++ { - minersRand := rand.Float64() + minersRand := r.Float64() j := 0 for ; j < MaxBlocks; j++ { minersRand -= winnerProba[j] diff --git a/pkg/repo/fskeystore/fskeystore_test.go b/pkg/repo/fskeystore/fskeystore_test.go index fbbbc2455c..1bafff4e8e 100644 --- a/pkg/repo/fskeystore/fskeystore_test.go +++ b/pkg/repo/fskeystore/fskeystore_test.go @@ -2,8 +2,8 @@ package fskeystore import ( "bytes" + "crypto/rand" "fmt" - "math/rand" "os" "path/filepath" "sort" 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/fr32/fr32_test.go b/pkg/util/fr32/fr32_test.go index a222632bb3..cd711b1ea9 100644 --- a/pkg/util/fr32/fr32_test.go +++ b/pkg/util/fr32/fr32_test.go @@ -2,8 +2,8 @@ package fr32_test import ( "bytes" + "crypto/rand" "io" - "math/rand" "os" "testing" @@ -74,7 +74,8 @@ func TestPadChunkRandEqFFI(t *testing.T) { tf.UnitTest(t) for i := 0; i < 200; i++ { var input [127]byte - rand.Read(input[:]) + _, err := rand.Read(input[:]) + require.NoError(t, err) var buf [128]byte @@ -113,7 +114,8 @@ func TestRoundtripChunkRand(t *testing.T) { tf.UnitTest(t) for i := 0; i < 200; i++ { var input [127]byte - rand.Read(input[:]) + _, err := rand.Read(input[:]) + require.NoError(t, err) var buf [128]byte copy(buf[:], input[:]) @@ -132,7 +134,8 @@ func TestRoundtrip16MRand(t *testing.T) { up := abi.PaddedPieceSize(16 << 20).Unpadded() input := make([]byte, up) - rand.Read(input[:]) + _, err := rand.Read(input[:]) + require.NoError(t, err) buf := make([]byte, 16<<20) 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 eeda9eebad..530d23f3b6 100644 --- a/venus-shared/testutil/value_provider_primitive.go +++ b/venus-shared/testutil/value_provider_primitive.go @@ -4,6 +4,9 @@ import ( "encoding/hex" "math/rand" "testing" + "time" + + "github.com/stretchr/testify/require" ) func init() { @@ -17,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 { @@ -26,14 +29,23 @@ 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) - rand.Read(b[:]) + _, err := r.Read(b[:]) + require.NoError(t, err) return b } } @@ -41,7 +53,8 @@ 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)) - rand.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 65bf21d56c..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.Seed(seed) - return rand.New(rand.NewSource(seed)) -} - func TestDefaultBytes(t *testing.T) { tf.UnitTest(t)