fix tests

This commit is contained in:
vyzo 2020-09-07 15:52:45 +03:00
parent 4f0ab4f226
commit d9faff19a5
4 changed files with 33 additions and 6 deletions

View File

@ -46,6 +46,8 @@ func init() {
}
power.ConsensusMinerMinPower = big.NewInt(2048)
verifreg.MinVerifiedDealSize = big.NewInt(256)
modules.PubsubSubscribeImmediately = true
}
const source = 0

View File

@ -29,6 +29,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules"
"github.com/filecoin-project/lotus/api/test"
"github.com/filecoin-project/lotus/chain/wallet"
@ -44,6 +45,8 @@ func init() {
abi.RegisteredSealProof_StackedDrg2KiBV1: {},
}
verifreg.MinVerifiedDealSize = big.NewInt(256)
modules.PubsubSubscribeImmediately = true
}
// TestPaymentChannels does a basic test to exercise the payment channel CLI

View File

@ -31,6 +31,9 @@ import (
"github.com/filecoin-project/lotus/node/modules/helpers"
)
// for tests
var PubsubSubscribeImmediately = false
func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.Service) error {
h.SetStreamHandler(hello.ProtocolID, svc.HandleStream)
@ -126,8 +129,7 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P
panic(err)
}
// wait until we are synced within 10 blocks
waitForSync(stmgr, 10, func() {
subscribe := func() {
log.Infof("subscribing to pubsub topic %s", build.BlocksTopic(nn))
blocksub, err := ps.Subscribe(build.BlocksTopic(nn)) //nolint
@ -136,7 +138,16 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P
}
go sub.HandleIncomingBlocks(ctx, blocksub, s, bserv, h.ConnManager())
})
}
// for tests
if PubsubSubscribeImmediately {
subscribe()
return
}
// wait until we are synced within 10 blocks
waitForSync(stmgr, 10, subscribe)
}
func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, stmgr *stmgr.StateManager, mpool *messagepool.MessagePool, h host.Host, nn dtypes.NetworkName) {
@ -148,8 +159,7 @@ func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub
panic(err)
}
// wait until we are synced within 1 block
waitForSync(stmgr, 1, func() {
subscribe := func() {
log.Infof("subscribing to pubsub topic %s", build.MessagesTopic(nn))
msgsub, err := ps.Subscribe(build.MessagesTopic(nn)) //nolint
@ -158,7 +168,16 @@ func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub
}
go sub.HandleIncomingMessages(ctx, mpool, msgsub)
})
}
// for tests
if PubsubSubscribeImmediately {
subscribe()
return
}
// wait until we are synced within 1 block
waitForSync(stmgr, 1, subscribe)
}
func NewLocalDiscovery(ds dtypes.MetadataDS) *discovery.Local {

View File

@ -16,6 +16,7 @@ import (
logging "github.com/ipfs/go-log/v2"
"github.com/filecoin-project/lotus/api/test"
"github.com/filecoin-project/lotus/node/modules"
)
func init() {
@ -26,6 +27,8 @@ func init() {
abi.RegisteredSealProof_StackedDrg2KiBV1: {},
}
verifreg.MinVerifiedDealSize = big.NewInt(256)
modules.PubsubSubscribeImmediately = true
}
func TestAPI(t *testing.T) {