pubsub_test.go 460 B

12345678910111213141516171819202122232425262728293031323334
  1. package pubsub_test
  2. import (
  3. "testing"
  4. . "github.com/xtls/xray-core/common/signal/pubsub"
  5. )
  6. func TestPubsub(t *testing.T) {
  7. service := NewService()
  8. sub := service.Subscribe("a")
  9. service.Publish("a", 1)
  10. select {
  11. case v := <-sub.Wait():
  12. if v != 1 {
  13. t.Error("expected subscribed value 1, but got ", v)
  14. }
  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. }