func TestAddListenerForEventFireMany(t *testing.T) {
	evsw := NewEventSwitch()
	err := evsw.Start()
	require.NoError(t, err)
	t.Cleanup(func() {
		if err := evsw.Stop(); err != nil {
			t.Error(err)
		}
	})
	doneSum := make(chan uint64)
	doneSending := make(chan uint64)
	numbers := make(chan uint64, 4)
	err = evsw.AddListenerForEvent("listener", "event",
		func(data EventData) {
			numbers <- data.(uint64)
		})
	require.NoError(t, err)
	go sumReceivedNumbers(numbers, doneSum)
	go fireEvents(evsw, "event", doneSending, uint64(1))
	checkSum := <-doneSending
	close(numbers)
	eventSum := <-doneSum
	if checkSum != eventSum {
		t.Errorf("not all messages sent were received.\n")
	}
}
TestAddListenerForEventFireMany sets up an EventSwitch, subscribes a single
listener to an event, and sends a thousand integers.
package events
import (
	"fmt"
	"testing"
	"time"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"github.com/tendermint/tendermint/libs/rand"
)
func TestAddListenerForEventFireOnce(t *testing.T) {
	evsw := NewEventSwitch()
	err := evsw.Start()
	require.NoError(t, err)
	t.Cleanup(func() {
		if err := evsw.Stop(); err != nil {
			t.Error(err)
		}
	})
	messages := make(chan EventData)
	err = evsw.AddListenerForEvent("listener", "event",
		func(data EventData) {
			evsw.RemoveListener("listener")
			messages <- data
		})
	require.NoError(t, err)
	go evsw.FireEvent("event", "data")
	received := <-messages
	if received != "data" {
		t.Errorf("message received does not match: %v", received)
	}
}