diff --git a/tm2/pkg/bft/consensus/common_test.go b/tm2/pkg/bft/consensus/common_test.go index ba19881aace..d251eebdbe0 100644 --- a/tm2/pkg/bft/consensus/common_test.go +++ b/tm2/pkg/bft/consensus/common_test.go @@ -246,7 +246,7 @@ func validatePrevoteAndPrecommit(t *testing.T, cs *ConsensusState, thisRound, lo } func subscribeToVoter(cs *ConsensusState, addr crypto.Address) <-chan events.Event { - return events.SubscribeFiltered(cs.evsw, testSubscriber, func(event events.Event) bool { + ch := events.SubscribeFiltered(cs.evsw, testSubscriber, func(event events.Event) bool { if vote, ok := event.(types.EventVote); ok { if vote.Vote.ValidatorAddress == addr { return true @@ -254,6 +254,16 @@ func subscribeToVoter(cs *ConsensusState, addr crypto.Address) <-chan events.Eve } return false }) + + testch := make(chan events.Event) + go func() { + defer close(testch) + for evt := range ch { + testch <- evt + } + }() + + return testch } // ------------------------------------------------------------------------------- diff --git a/tm2/pkg/bft/consensus/state_test.go b/tm2/pkg/bft/consensus/state_test.go index 5839975b39d..1690de2c03c 100644 --- a/tm2/pkg/bft/consensus/state_test.go +++ b/tm2/pkg/bft/consensus/state_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "reflect" - "sync/atomic" "testing" "time" @@ -1451,6 +1450,7 @@ func TestStartNextHeightCorrectly(t *testing.T) { ensureNewRound(newRoundCh, height, round) ensureNewProposal(proposalCh, height, round) + rs := cs1.GetRoundState() theBlockHash := rs.ProposalBlock.Hash() theBlockParts := rs.ProposalBlockParts.Header() @@ -1480,6 +1480,7 @@ func TestStartNextHeightCorrectly(t *testing.T) { height, round = height+1, 0 ensureNewRound(newRoundCh, height, round) ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) + rs = cs1.GetRoundState() assert.False(t, rs.TriggeredTimeoutPrecommit, "triggeredTimeoutPrecommit should be false at the beginning of each round") } @@ -1781,11 +1782,18 @@ func TestStateOutputVoteStats(t *testing.T) { } } -var eventid uint32 - func subscribe(evsw events.EventSwitch, protoevent events.Event) <-chan events.Event { name := reflect.ValueOf(protoevent).Type().Name() - id := atomic.AddUint32(&eventid, 1) - listenerID := fmt.Sprintf("%s-%s-%d", testSubscriber, name, id) - return events.SubscribeToEvent(evsw, listenerID, protoevent) + listenerID := fmt.Sprintf("%s-%s", testSubscriber, name) + ch := events.SubscribeToEvent(evsw, listenerID, protoevent) + + testch := make(chan events.Event, 16) + go func() { + defer close(testch) + for evt := range ch { + testch <- evt + } + }() + + return testch }