Browse Source

Merge pull request #497 from tendermint/feature/color-code-different-consensus-instances

Color code different consensus instances in consensus tests
pull/447/merge
Ethan Buchman 8 years ago
committed by GitHub
parent
commit
0f1edcd57d
4 changed files with 39 additions and 15 deletions
  1. +6
    -5
      consensus/byzantine_test.go
  2. +18
    -2
      consensus/common_test.go
  3. +3
    -3
      consensus/reactor_test.go
  4. +12
    -5
      glide.lock

+ 6
- 5
consensus/byzantine_test.go View File

@ -9,7 +9,6 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common" . "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/events" "github.com/tendermint/tmlibs/events"
"github.com/tendermint/tmlibs/log"
) )
func init() { func init() {
@ -27,16 +26,17 @@ func init() {
// Heal partition and ensure A sees the commit // Heal partition and ensure A sees the commit
func TestByzantine(t *testing.T) { func TestByzantine(t *testing.T) {
N := 4 N := 4
logger := consensusLogger()
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()) css[0].SetTimeoutTicker(NewTimeoutTicker())
switches := make([]*p2p.Switch, N) switches := make([]*p2p.Switch, N)
p2pLogger := log.TestingLogger().With("module", "p2p")
p2pLogger := logger.With("module", "p2p")
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
switches[i] = p2p.NewSwitch(config.P2P) switches[i] = p2p.NewSwitch(config.P2P)
switches[i].SetLogger(p2pLogger)
switches[i].SetLogger(p2pLogger.With("validator", i))
} }
reactors := make([]p2p.Reactor, N) reactors := make([]p2p.Reactor, N)
@ -50,6 +50,7 @@ func TestByzantine(t *testing.T) {
} }
}() }()
eventChans := make([]chan interface{}, N) eventChans := make([]chan interface{}, N)
eventLogger := logger.With("module", "events")
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
if i == 0 { if i == 0 {
css[i].privValidator = NewByzantinePrivValidator(css[i].privValidator.(*types.PrivValidator)) css[i].privValidator = NewByzantinePrivValidator(css[i].privValidator.(*types.PrivValidator))
@ -63,7 +64,7 @@ func TestByzantine(t *testing.T) {
} }
eventSwitch := events.NewEventSwitch() eventSwitch := events.NewEventSwitch()
eventSwitch.SetLogger(log.TestingLogger().With("module", "events"))
eventSwitch.SetLogger(eventLogger.With("validator", i))
_, err := eventSwitch.Start() _, err := eventSwitch.Start()
if err != nil { if err != nil {
t.Fatalf("Failed to start switch: %v", err) t.Fatalf("Failed to start switch: %v", err)
@ -71,7 +72,7 @@ func TestByzantine(t *testing.T) {
eventChans[i] = subscribeToEvent(eventSwitch, "tester", types.EventStringNewBlock(), 1) eventChans[i] = subscribeToEvent(eventSwitch, "tester", types.EventStringNewBlock(), 1)
conR := NewConsensusReactor(css[i], true) // so we dont start the consensus states conR := NewConsensusReactor(css[i], true) // so we dont start the consensus states
conR.SetLogger(log.TestingLogger())
conR.SetLogger(logger.With("validator", i))
conR.SetEventSwitch(eventSwitch) conR.SetEventSwitch(eventSwitch)
var conRI p2p.Reactor var conRI p2p.Reactor


+ 18
- 2
consensus/common_test.go View File

@ -25,6 +25,8 @@ import (
"github.com/tendermint/abci/example/counter" "github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/example/dummy" "github.com/tendermint/abci/example/dummy"
"github.com/go-kit/kit/log/term"
) )
// genesis, chain_id, priv_val // genesis, chain_id, priv_val
@ -325,18 +327,32 @@ func ensureNoNewStep(stepCh chan interface{}) {
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// consensus nets // consensus nets
// consensusLogger is a TestingLogger which uses a different
// color for each validator ("validator" key must exist).
func consensusLogger() log.Logger {
return log.TestingLoggerWithColorFn(func(keyvals ...interface{}) term.FgBgColor {
for i := 0; i < len(keyvals)-1; i += 2 {
if keyvals[i] == "validator" {
return term.FgBgColor{Fg: term.Color(uint8(keyvals[i+1].(int) + 1))}
}
}
return term.FgBgColor{}
})
}
func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState { func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
genDoc, privVals := randGenesisDoc(nValidators, false, 10) genDoc, privVals := randGenesisDoc(nValidators, false, 10)
css := make([]*ConsensusState, nValidators) css := make([]*ConsensusState, nValidators)
logger := consensusLogger()
for i := 0; i < nValidators; i++ { for i := 0; i < nValidators; i++ {
db := dbm.NewMemDB() // each state needs its own db db := dbm.NewMemDB() // each state needs its own db
state := sm.MakeGenesisState(db, genDoc) state := sm.MakeGenesisState(db, genDoc)
state.SetLogger(log.TestingLogger().With("module", "state"))
state.SetLogger(logger.With("module", "state", "validator", i))
state.Save() state.Save()
thisConfig := ResetConfig(Fmt("%s_%d", testName, i)) thisConfig := ResetConfig(Fmt("%s_%d", testName, i))
ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], appFunc()) css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], appFunc())
css[i].SetLogger(log.TestingLogger())
css[i].SetLogger(logger.With("validator", i))
css[i].SetTimeoutTicker(tickerFunc()) css[i].SetTimeoutTicker(tickerFunc())
} }
return css return css


+ 3
- 3
consensus/reactor_test.go View File

@ -10,7 +10,6 @@ import (
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/events" "github.com/tendermint/tmlibs/events"
"github.com/tendermint/tmlibs/log"
) )
func init() { func init() {
@ -23,12 +22,13 @@ func init() {
func startConsensusNet(t *testing.T, css []*ConsensusState, N int, subscribeEventRespond bool) ([]*ConsensusReactor, []chan interface{}) { func startConsensusNet(t *testing.T, css []*ConsensusState, N int, subscribeEventRespond bool) ([]*ConsensusReactor, []chan interface{}) {
reactors := make([]*ConsensusReactor, N) reactors := make([]*ConsensusReactor, N)
eventChans := make([]chan interface{}, N) eventChans := make([]chan interface{}, N)
logger := consensusLogger()
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
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(log.TestingLogger().With("reactor", i))
reactors[i].SetLogger(logger.With("validator", i))
eventSwitch := events.NewEventSwitch() eventSwitch := events.NewEventSwitch()
eventSwitch.SetLogger(log.TestingLogger().With("module", "events"))
eventSwitch.SetLogger(logger.With("module", "events", "validator", i))
_, err := eventSwitch.Start() _, err := eventSwitch.Start()
if err != nil { if err != nil {
t.Fatalf("Failed to start switch: %v", err) t.Fatalf("Failed to start switch: %v", err)


+ 12
- 5
glide.lock View File

@ -1,10 +1,12 @@
hash: 9caff08aa026986b239e4aeb9d876bdddfacadc64a660ee8109e77a211e53436 hash: 9caff08aa026986b239e4aeb9d876bdddfacadc64a660ee8109e77a211e53436
updated: 2017-05-13T14:12:48.997991788Z
updated: 2017-05-15T07:32:38.823266751Z
imports: imports:
- name: github.com/btcsuite/btcd - name: github.com/btcsuite/btcd
version: 1ae306021e323ae11c71ffb8546fbd9019e6cb6f version: 1ae306021e323ae11c71ffb8546fbd9019e6cb6f
subpackages: subpackages:
- btcec - btcec
- name: github.com/clipperhouse/typewriter
version: c1a48da378ebb7db1db9f35981b5cc24bf2e5b85
- name: github.com/davecgh/go-spew - name: github.com/davecgh/go-spew
version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
subpackages: subpackages:
@ -74,7 +76,7 @@ imports:
- name: github.com/spf13/cast - name: github.com/spf13/cast
version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4 version: acbeb36b902d72a7a4c18e8f3241075e7ab763e4
- name: github.com/spf13/cobra - name: github.com/spf13/cobra
version: 90687e7bfc7e1e5cd88eb1f513f32f01dc03dd7c
version: e9078fccb8b1e6914310b96d5e1be43713f3a372
- name: github.com/spf13/jwalterweatherman - name: github.com/spf13/jwalterweatherman
version: 8f07c835e5cc1450c082fe3a439cf87b0cbb2d99 version: 8f07c835e5cc1450c082fe3a439cf87b0cbb2d99
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
@ -117,7 +119,7 @@ imports:
- name: github.com/tendermint/go-crypto - name: github.com/tendermint/go-crypto
version: e71bbb2509b586f0b24f120b6ba57f32aefa1579 version: e71bbb2509b586f0b24f120b6ba57f32aefa1579
- name: github.com/tendermint/go-wire - name: github.com/tendermint/go-wire
version: 82d31b6afb3c438639bffc5e1c7318b9a55285b3
version: 8b47d1a9dd4e94ee0e099216c382847342405ab9
subpackages: subpackages:
- data - data
- data/base58 - data/base58
@ -129,7 +131,7 @@ imports:
- iavl - iavl
- testutil - testutil
- name: github.com/tendermint/tmlibs - name: github.com/tendermint/tmlibs
version: 8f5a175ff4c869fedde710615a11f5745ff69bf3
version: 4fdeaa70afa2556360a396faaa82e640b9912b0c
subpackages: subpackages:
- autofile - autofile
- cli - cli
@ -163,7 +165,7 @@ imports:
- lex/httplex - lex/httplex
- trace - trace
- name: golang.org/x/sys - name: golang.org/x/sys
version: f845067cf72a21fb4929b0e6a35273bd83b56396
version: 1e99a4f9d247b28c670884b9a8d6801f39a47b77
subpackages: subpackages:
- unix - unix
- name: golang.org/x/text - name: golang.org/x/text
@ -173,6 +175,11 @@ imports:
- transform - transform
- unicode/bidi - unicode/bidi
- unicode/norm - unicode/norm
- name: golang.org/x/tools
version: 144c6642b5d832d6c44a53dad6ee61665dd432ce
subpackages:
- go/ast/astutil
- imports
- name: google.golang.org/genproto - name: google.golang.org/genproto
version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 version: 411e09b969b1170a9f0c467558eb4c4c110d9c77
subpackages: subpackages:


Loading…
Cancel
Save