Browse Source

consensus: fix SetLogger in tests

pull/1154/head
Ethan Buchman 7 years ago
parent
commit
3ae26bd6e6
4 changed files with 9 additions and 16 deletions
  1. +1
    -1
      config/config.go
  2. +3
    -1
      consensus/byzantine_test.go
  3. +4
    -13
      consensus/common_test.go
  4. +1
    -1
      consensus/reactor_test.go

+ 1
- 1
config/config.go View File

@ -451,7 +451,7 @@ func TestConsensusConfig() *ConsensusConfig {
config.TimeoutCommit = 10 config.TimeoutCommit = 10
config.SkipTimeoutCommit = true config.SkipTimeoutCommit = true
config.PeerGossipSleepDuration = 5 config.PeerGossipSleepDuration = 5
config.PeerQueryMaj23SleepDuration = 50
config.PeerQueryMaj23SleepDuration = 250
return config return config
} }


+ 3
- 1
consensus/byzantine_test.go View File

@ -33,7 +33,9 @@ func TestByzantine(t *testing.T) {
css := randConsensusNet(N, "consensus_byzantine_test", newMockTickerFunc(false), newCounter) css := randConsensusNet(N, "consensus_byzantine_test", newMockTickerFunc(false), newCounter)
// give the byzantine validator a normal ticker // give the byzantine validator a normal ticker
css[0].SetTimeoutTicker(NewTimeoutTicker())
ticker := NewTimeoutTicker()
ticker.SetLogger(css[0].Logger)
css[0].SetTimeoutTicker(ticker)
switches := make([]*p2p.Switch, N) switches := make([]*p2p.Switch, N)
p2pLogger := logger.With("module", "p2p") p2pLogger := logger.With("module", "p2p")


+ 4
- 13
consensus/common_test.go View File

@ -267,7 +267,7 @@ func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.S
stateDB := dbm.NewMemDB() stateDB := dbm.NewMemDB()
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool) blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool) cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
cs.SetLogger(log.TestingLogger())
cs.SetLogger(log.TestingLogger().With("module", "consensus"))
cs.SetPrivValidator(pv) cs.SetPrivValidator(pv)
eventBus := types.NewEventBus() eventBus := types.NewEventBus()
@ -285,14 +285,6 @@ func loadPrivValidator(config *cfg.Config) *types.PrivValidatorFS {
return privValidator return privValidator
} }
func fixedConsensusStateDummy(config *cfg.Config, logger log.Logger) *ConsensusState {
state, _ := sm.MakeGenesisStateFromFile(config.GenesisFile())
privValidator := loadPrivValidator(config)
cs := newConsensusState(state, privValidator, dummy.NewDummyApplication())
cs.SetLogger(logger)
return cs
}
func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) { func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
// Get State // Get State
state, privVals := randGenesisState(nValidators, false, 10) state, privVals := randGenesisState(nValidators, false, 10)
@ -300,7 +292,6 @@ func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
vss := make([]*validatorStub, nValidators) vss := make([]*validatorStub, nValidators)
cs := newConsensusState(state, privVals[0], counter.NewCounterApplication(true)) cs := newConsensusState(state, privVals[0], counter.NewCounterApplication(true))
cs.SetLogger(log.TestingLogger())
for i := 0; i < nValidators; i++ { for i := 0; i < nValidators; i++ {
vss[i] = NewValidatorStub(privVals[i], i) vss[i] = NewValidatorStub(privVals[i], i)
@ -346,7 +337,7 @@ func consensusLogger() log.Logger {
} }
} }
return term.FgBgColor{} return term.FgBgColor{}
})
}).With("module", "consensus")
} }
func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application, configOpts ...func(*cfg.Config)) []*ConsensusState { func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application, configOpts ...func(*cfg.Config)) []*ConsensusState {
@ -366,8 +357,8 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
app.InitChain(abci.RequestInitChain{Validators: vals}) app.InitChain(abci.RequestInitChain{Validators: vals})
css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app) css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
css[i].SetLogger(logger.With("validator", i))
css[i].SetTimeoutTicker(tickerFunc()) css[i].SetTimeoutTicker(tickerFunc())
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
} }
return css return css
} }
@ -395,8 +386,8 @@ func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerF
app.InitChain(abci.RequestInitChain{Validators: vals}) app.InitChain(abci.RequestInitChain{Validators: vals})
css[i] = newConsensusStateWithConfig(thisConfig, state, privVal, app) css[i] = newConsensusStateWithConfig(thisConfig, state, privVal, app)
css[i].SetLogger(logger.With("validator", i))
css[i].SetTimeoutTicker(tickerFunc()) css[i].SetTimeoutTicker(tickerFunc())
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
} }
return css return css
} }


+ 1
- 1
consensus/reactor_test.go View File

@ -35,7 +35,7 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int) ([]*Consensus
/*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info") /*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info")
if err != nil { t.Fatal(err)}*/ if err != nil { t.Fatal(err)}*/
reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states
reactors[i].SetLogger(css[i].Logger.With("validator", "i", "module", "consensus"))
reactors[i].SetLogger(css[i].Logger)
// eventBus is already started with the cs // eventBus is already started with the cs
eventBuses[i] = css[i].eventBus eventBuses[i] = css[i].eventBus


Loading…
Cancel
Save