Browse Source

refactor TestNoBlockMessageResponse to eliminate a race condition

pull/765/head
Anton Kaliaev 7 years ago
parent
commit
e06bbaf303
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 10 additions and 17 deletions
  1. +10
    -17
      blockchain/reactor_test.go

+ 10
- 17
blockchain/reactor_test.go View File

@ -1,12 +1,11 @@
package blockchain package blockchain
import ( import (
"bytes"
"testing" "testing"
wire "github.com/tendermint/go-wire" wire "github.com/tendermint/go-wire"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/db"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/log"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
@ -15,28 +14,24 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
func newBlockchainReactor(logger log.Logger, maxBlockHeight int) *BlockchainReactor {
config := cfg.ResetTestRoot("node_node_test")
func newBlockchainReactor(maxBlockHeight int) *BlockchainReactor {
logger := log.TestingLogger()
config := cfg.ResetTestRoot("blockchain_reactor_test")
blockStoreDB := db.NewDB("blockstore", config.DBBackend, config.DBDir())
blockStore := NewBlockStore(blockStoreDB)
stateLogger := logger.With("module", "state")
blockStore := NewBlockStore(dbm.NewMemDB())
// Get State // Get State
stateDB := db.NewDB("state", config.DBBackend, config.DBDir())
state, _ := sm.GetState(stateDB, config.GenesisFile())
state.SetLogger(stateLogger)
state, _ := sm.GetState(dbm.NewMemDB(), config.GenesisFile())
state.SetLogger(logger.With("module", "state"))
state.Save() state.Save()
// Make the blockchainReactor itself // Make the blockchainReactor itself
fastSync := true fastSync := true
bcReactor := NewBlockchainReactor(state.Copy(), nil, blockStore, fastSync) bcReactor := NewBlockchainReactor(state.Copy(), nil, blockStore, fastSync)
bcReactor.SetLogger(logger.With("module", "blockchain"))
// Next: we need to set a switch in order for peers to be added in // Next: we need to set a switch in order for peers to be added in
bcReactor.Switch = p2p.NewSwitch(cfg.DefaultP2PConfig()) bcReactor.Switch = p2p.NewSwitch(cfg.DefaultP2PConfig())
bcReactor.SetLogger(logger.With("module", "blockchain"))
// Lastly: let's add some blocks in // Lastly: let's add some blocks in
for blockHeight := 1; blockHeight <= maxBlockHeight; blockHeight++ { for blockHeight := 1; blockHeight <= maxBlockHeight; blockHeight++ {
@ -50,12 +45,10 @@ func newBlockchainReactor(logger log.Logger, maxBlockHeight int) *BlockchainReac
} }
func TestNoBlockMessageResponse(t *testing.T) { func TestNoBlockMessageResponse(t *testing.T) {
logBuf := new(bytes.Buffer)
logger := log.NewTMLogger(logBuf)
maxBlockHeight := 20 maxBlockHeight := 20
bcr := newBlockchainReactor(logger, maxBlockHeight)
go bcr.OnStart()
bcr := newBlockchainReactor(maxBlockHeight)
bcr.Start()
defer bcr.Stop() defer bcr.Stop()
// Add some peers in // Add some peers in


Loading…
Cancel
Save