github.com/supragya/TendermintConnector@v0.0.0-20210619045051-113e32b84fb1/chains/tm34/libs/events/event_cache_test.go (about) 1 package events 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestEventCache_Flush(t *testing.T) { 11 evsw := NewEventSwitch() 12 err := evsw.Start() 13 require.NoError(t, err) 14 15 err = evsw.AddListenerForEvent("nothingness", "", func(data EventData) { 16 // Check we are not initialising an empty buffer full of zeroed eventInfos in the EventCache 17 require.FailNow(t, "We should never receive a message on this switch since none are fired") 18 }) 19 require.NoError(t, err) 20 21 evc := NewEventCache(evsw) 22 evc.Flush() 23 // Check after reset 24 evc.Flush() 25 fail := true 26 pass := false 27 err = evsw.AddListenerForEvent("somethingness", "something", func(data EventData) { 28 if fail { 29 require.FailNow(t, "Shouldn't see a message until flushed") 30 } 31 pass = true 32 }) 33 require.NoError(t, err) 34 35 evc.FireEvent("something", struct{ int }{1}) 36 evc.FireEvent("something", struct{ int }{2}) 37 evc.FireEvent("something", struct{ int }{3}) 38 fail = false 39 evc.Flush() 40 assert.True(t, pass) 41 }