From 0ada0cf525912bf376fff4cd5e733e53fad3f0e3 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 12 Nov 2017 00:43:16 +0000 Subject: [PATCH 1/3] certifiers: test uses WaitForHeight --- certifiers/client/provider.go | 5 +++++ certifiers/client/provider_test.go | 13 ++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/certifiers/client/provider.go b/certifiers/client/provider.go index 6240da11c..0c0add6a1 100644 --- a/certifiers/client/provider.go +++ b/certifiers/client/provider.go @@ -40,6 +40,11 @@ func NewHTTPProvider(remote string) certifiers.Provider { } } +// StatusClient returns the internal node as a StatusClient +func (p *provider) StatusClient() rpcclient.StatusClient { + return p.node +} + // StoreCommit is a noop, as clients can only read from the chain... func (p *provider) StoreCommit(_ certifiers.FullCommit) error { return nil } diff --git a/certifiers/client/provider_test.go b/certifiers/client/provider_test.go index c63cd6a1e..82955c22f 100644 --- a/certifiers/client/provider_test.go +++ b/certifiers/client/provider_test.go @@ -1,17 +1,15 @@ -package client_test +package client import ( "testing" - "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - rpctest "github.com/tendermint/tendermint/rpc/test" - "github.com/tendermint/tendermint/certifiers" - "github.com/tendermint/tendermint/certifiers/client" certerr "github.com/tendermint/tendermint/certifiers/errors" + rpcclient "github.com/tendermint/tendermint/rpc/client" + rpctest "github.com/tendermint/tendermint/rpc/test" ) func TestProvider(t *testing.T) { @@ -20,11 +18,12 @@ func TestProvider(t *testing.T) { cfg := rpctest.GetConfig() rpcAddr := cfg.RPC.ListenAddress chainID := cfg.ChainID - p := client.NewHTTPProvider(rpcAddr) + p := NewHTTPProvider(rpcAddr) require.NotNil(t, p) // let it produce some blocks - time.Sleep(500 * time.Millisecond) + err := rpcclient.WaitForHeight(p.(*provider).node, 6, nil) + require.Nil(err) // let's get the highest block seed, err := p.LatestCommit() From 0448c2b437c7d17fe176d745fe25dae8a16ebc52 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 12 Nov 2017 06:40:27 +0000 Subject: [PATCH 2/3] consensus: fix LastCommit log --- consensus/reactor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 050fdfa40..026d8e076 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -1056,8 +1056,8 @@ func (ps *PeerState) SetHasVote(vote *types.Vote) { } func (ps *PeerState) setHasVote(height int, round int, type_ byte, index int) { - logger := ps.logger.With("peerRound", ps.Round, "height", height, "round", round) - logger.Debug("setHasVote(LastCommit)", "lastCommit", ps.LastCommit, "index", index) + logger := ps.logger.With("peerH/R", cmn.Fmt("%d/%d", ps.Height, ps.Round), "H/R", cmn.Fmt("%d/%d", height, round)) + logger.Debug("setHasVote", "type", type_, "index", index) // NOTE: some may be nil BitArrays -> no side effects. psVotes := ps.getVoteBitArray(height, round, type_) From aba8a8f4fcaca3792f3136c6ad7144a5807d1942 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 12 Nov 2017 06:41:15 +0000 Subject: [PATCH 3/3] consensus: crank timeout in timeoutWaitGroup --- consensus/reactor_test.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 05a422da9..32fb733f7 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -3,6 +3,8 @@ package consensus import ( "context" "fmt" + "os" + "runtime/pprof" "sync" "testing" "time" @@ -29,11 +31,16 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int) ([]*Consensus eventBuses := make([]*types.EventBus, N) logger := consensusLogger() for i := 0; i < N; i++ { + /*thisLogger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info") + if err != nil { t.Fatal(err)}*/ + thisLogger := logger + reactors[i] = NewConsensusReactor(css[i], true) // so we dont start the consensus states - reactors[i].SetLogger(logger.With("validator", i)) + reactors[i].conS.SetLogger(thisLogger.With("validator", i)) + reactors[i].SetLogger(thisLogger.With("validator", i)) eventBuses[i] = types.NewEventBus() - eventBuses[i].SetLogger(logger.With("module", "events", "validator", i)) + eventBuses[i].SetLogger(thisLogger.With("module", "events", "validator", i)) _, err := eventBuses[i].Start() require.NoError(t, err) @@ -52,6 +59,7 @@ func startConsensusNet(t *testing.T, css []*ConsensusState, N int) ([]*Consensus // now that everyone is connected, start the state machines // If we started the state machines before everyone was connected, // we'd block when the cs fires NewBlockEvent and the peers are trying to start their reactors + // TODO: is this still true with new pubsub? for i := 0; i < N; i++ { s := reactors[i].conS.GetState() reactors[i].SwitchToConsensus(s, 0) @@ -304,7 +312,7 @@ func waitForAndValidateBlock(t *testing.T, n int, activeVals map[string]struct{} }, css) } -func waitForBlockWithUpdatedValsAndValidateIt(t *testing.T, n int, updatedVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState, txs ...[]byte) { +func waitForBlockWithUpdatedValsAndValidateIt(t *testing.T, n int, updatedVals map[string]struct{}, eventChans []chan interface{}, css []*ConsensusState) { timeoutWaitGroup(t, n, func(wg *sync.WaitGroup, j int) { var newBlock *types.Block LOOP: @@ -355,15 +363,20 @@ func timeoutWaitGroup(t *testing.T, n int, f func(*sync.WaitGroup, int), css []* close(done) }() + // we're running many nodes in-process, possibly in in a virtual machine, + // and spewing debug messages - making a block could take a while, + timeout := time.Second * 60 + select { case <-done: - case <-time.After(time.Second * 10): + case <-time.After(timeout): for i, cs := range css { - fmt.Println("#################") - fmt.Println("Validator", i) - fmt.Println(cs.GetRoundState()) - fmt.Println("") + t.Log("#################") + t.Log("Validator", i) + t.Log(cs.GetRoundState()) + t.Log("") } + pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) panic("Timed out waiting for all validators to commit a block") } }