github.com/xmplusdev/xray-core@v1.8.10/common/signal/pubsub/pubsub_test.go (about) 1 package pubsub_test 2 3 import ( 4 "testing" 5 6 . "github.com/xmplusdev/xray-core/common/signal/pubsub" 7 ) 8 9 func TestPubsub(t *testing.T) { 10 service := NewService() 11 12 sub := service.Subscribe("a") 13 service.Publish("a", 1) 14 15 select { 16 case v := <-sub.Wait(): 17 if v != 1 { 18 t.Error("expected subscribed value 1, but got ", v) 19 } 20 default: 21 t.Fail() 22 } 23 24 sub.Close() 25 service.Publish("a", 2) 26 27 select { 28 case <-sub.Wait(): 29 t.Fail() 30 default: 31 } 32 33 service.Cleanup() 34 }