diff --git a/tm2/pkg/bft/consensus/common_test.go b/tm2/pkg/bft/consensus/common_test.go index ba19881aace..3f5b3a55e95 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, 16) + 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..262bbbea254 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" @@ -1781,11 +1780,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 }