pubsub_test.go 451 B

1234567891011121314151617181920212223242526272829303132333435
  1. package pubsub_test
  2. import (
  3. "testing"
  4. . "v2ray.com/core/common/signal/pubsub"
  5. . "v2ray.com/ext/assert"
  6. )
  7. func TestPubsub(t *testing.T) {
  8. assert := With(t)
  9. service := NewService()
  10. sub := service.Subscribe("a")
  11. service.Publish("a", 1)
  12. select {
  13. case v := <-sub.Wait():
  14. assert(v.(int), Equals, 1)
  15. default:
  16. t.Fail()
  17. }
  18. sub.Close()
  19. service.Publish("a", 2)
  20. select {
  21. case <-sub.Wait():
  22. t.Fail()
  23. default:
  24. }
  25. service.Cleanup()
  26. }