Skip to content

Commit

Permalink
fix: fix test error in venus-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Aug 8, 2022
1 parent 71a74ba commit 6ad020a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
./gengen --keypath ./fixtures/live --out-car ./fixtures/live/genesis.car --out-json ./fixtures/live/gen.json --config ./fixtures/setup.json
./gengen --keypath ./fixtures/test --out-car ./fixtures/test/genesis.car --out-json ./fixtures/test/gen.json --config ./fixtures/setup.json
- name: Integration Test
run: go test -coverpkg=./... -coverprofile=coverage_venus_shared.txt -covermode=atomic -timeout=30m -parallel=4 -v ./venus-shared/...

- name: Unit Test
run: go test -coverpkg=./... -coverprofile=coverage_unit.txt -covermode=atomic -timeout=30m -parallel=4 -v ./... -integration=false -unit=true

Expand All @@ -69,7 +72,7 @@ jobs:
uses: codecov/codecov-action@v2
with:
token:
files: ./coverage_unit.txt,./coverage_integration.txt
files: ./coverage_unit.txt,./coverage_integration.txt,./coverage_venus_shared.txt
flags: unittests,integration
name: venus
fail_ci_if_error: true
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ actor-render:
actor-replica:
cd venus-devtool && go run ./compatible/actors/*.go replica --dst ../venus-shared/actors/

test:
test:test-venus-shared
go build -o genesis-file-server ./tools/genesis-file-server
go build -o gengen ./tools/gengen
./gengen --keypath ./fixtures/live --out-car ./fixtures/live/genesis.car --out-json ./fixtures/live/gen.json --config ./fixtures/setup.json
./gengen --keypath ./fixtures/test --out-car ./fixtures/test/genesis.car --out-json ./fixtures/test/gen.json --config ./fixtures/setup.json
go test -v ./... -integration=true -unit=false
go test $(go list ./... | grep -v /venus-shared/) -unit=false

lint: $(BUILD_DEPS)
golangci-lint run
Expand Down
4 changes: 2 additions & 2 deletions app/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package node
import (
"context"
"fmt"
"time"

"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/network"
"time"

logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
Expand Down Expand Up @@ -127,7 +128,6 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
return nil, errors.Wrap(err, "failed to build node.dagservice")
}


nd.syncer, err = syncer.NewSyncerSubmodule(ctx, (*builder)(b), nd.blockstore, nd.network, nd.chain, nd.circulatiingSupplyCalculator)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Syncer")
Expand Down
5 changes: 3 additions & 2 deletions app/submodule/network/network_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"context"
"fmt"
"github.com/filecoin-project/venus/pkg/net/helloprotocol"
"os"
"runtime"
"time"

"github.com/filecoin-project/venus/pkg/net/helloprotocol"

"github.com/dchest/blake2b"
"github.com/ipfs/go-bitswap"
bsnet "github.com/ipfs/go-bitswap/network"
Expand Down Expand Up @@ -232,7 +233,7 @@ func NewNetworkSubmodule(ctx context.Context, chainStore *chain.Store,
DataTransferHost: dtNet,
PeerMgr: peerMgr,
HelloHandler: helloHandler,
cfg: config,
cfg: config,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion app/submodule/syncer/syncer_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func NewSyncerSubmodule(ctx context.Context,
return nil, err
}
}

network.HelloHandler.Register(func(ci *types.ChainInfo) {
err := chainSyncManager.BlockProposer().SendHello(ci)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/net/helloprotocol/hello_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type LatencyMessage struct {
// containing some information about the state of our chain,
// and receive the same information from them. This is used to
// initiate a chainsync and detect connections to forks.
type HelloProtocolHandler struct {
type HelloProtocolHandler struct { //nolint
host host.Host

genesis cid.Cid
Expand Down
26 changes: 10 additions & 16 deletions pkg/net/helloprotocol/hello_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package helloprotocol_test

import (
"context"
"github.com/filecoin-project/venus/pkg/net/helloprotocol"
"github.com/filecoin-project/venus/pkg/net/peermgr"
"testing"
"time"

"github.com/filecoin-project/venus/pkg/net/helloprotocol"
"github.com/filecoin-project/venus/pkg/net/peermgr"

ds "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p-core/host"
dht "github.com/libp2p/go-libp2p-kad-dht"
Expand Down Expand Up @@ -34,14 +35,6 @@ func (msb *mockHelloCallback) HelloCallback(ci *types.ChainInfo) {
msb.Called(ci.Sender, ci.Head.Key())
}

type mockHeaviestGetter struct {
heaviest *types.TipSet
}

func (mhg *mockHeaviestGetter) getHeaviestTipSet() (*types.TipSet, error) {
return mhg.heaviest, nil
}

func TestHelloHandshake(t *testing.T) {
tf.UnitTest(t)

Expand All @@ -60,7 +53,7 @@ func TestHelloHandshake(t *testing.T) {
store := builder.Store()
mstore := builder.Mstore()
heavy1 := builder.AppendOn(ctx, genesisA, 1)
oldStore := copyStoreAndSetHead(ctx, store, heavy1)
oldStore := copyStoreAndSetHead(ctx, t, store, heavy1)

heavy2 := builder.AppendOn(ctx, heavy1, 1)
_ = store.SetHead(ctx, heavy2)
Expand Down Expand Up @@ -125,7 +118,7 @@ func TestHelloBadGenesis(t *testing.T) {
genesisB := builder.AppendOn(ctx, types.UndefTipSet, 1)

heavy1 := builder.AppendOn(ctx, genesisA, 1)
oldStore := copyStoreAndSetHead(ctx, store, heavy1)
oldStore := copyStoreAndSetHead(ctx, t, store, heavy1)

heavy2 := builder.AppendOn(ctx, heavy1, 1)
_ = store.SetHead(ctx, heavy2)
Expand Down Expand Up @@ -172,7 +165,7 @@ func TestHelloMultiBlock(t *testing.T) {

heavy1 := builder.AppendOn(ctx, genesisTipset, 3)
heavy1 = builder.AppendOn(ctx, heavy1, 3)
oldStore := copyStoreAndSetHead(ctx, store, heavy1)
oldStore := copyStoreAndSetHead(ctx, t, store, heavy1)

heavy2 := builder.AppendOn(ctx, heavy1, 3)
_ = store.SetHead(ctx, heavy2)
Expand Down Expand Up @@ -204,8 +197,9 @@ func mockPeerMgr(ctx context.Context, t *testing.T, h host.Host) (*peermgr.PeerM
return peermgr.NewPeerMgr(h, dht.NewDHT(ctx, h, ds.NewMapDatastore()), 10, addrInfo)
}

func copyStoreAndSetHead(ctx context.Context, store *chain.Store, ts *types.TipSet) *chain.Store {
storeCopy := *store
storeCopy.SetHead(ctx, ts)
func copyStoreAndSetHead(ctx context.Context, t *testing.T, store *chain.Store, ts *types.TipSet) *chain.Store {
storeCopy := *store //nolint
err := storeCopy.SetHead(ctx, ts)
require.NoError(t, err)
return &storeCopy
}
6 changes: 3 additions & 3 deletions tools/gen_cbor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/filecoin-project/venus/pkg/chain"
"github.com/filecoin-project/venus/pkg/fvm"
"github.com/filecoin-project/venus/pkg/market"
"github.com/filecoin-project/venus/pkg/net"
"github.com/filecoin-project/venus/pkg/net/exchange"
"github.com/filecoin-project/venus/pkg/net/helloprotocol"
"github.com/filecoin-project/venus/pkg/paychmgr"
"github.com/filecoin-project/venus/pkg/state/tree"
"github.com/filecoin-project/venus/pkg/vm/dispatch"
Expand All @@ -28,8 +28,8 @@ func main() {
}

if err := gen.WriteTupleEncodersToFile("./pkg/discovery/cbor_gen.go", "discovery",
net.HelloMessage{},
net.LatencyMessage{},
helloprotocol.HelloMessage{},
helloprotocol.LatencyMessage{},
); err != nil {
panic(err)
}
Expand Down

0 comments on commit 6ad020a

Please sign in to comment.