You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
930 B

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