Xray-core/common/signal/pubsub/pubsub_test.go

35 lines
460 B
Go
Raw Normal View History

2020-11-25 11:01:53 +00:00
package pubsub_test
import (
"testing"
2020-12-04 01:36:16 +00:00
. "github.com/xtls/xray-core/common/signal/pubsub"
2020-11-25 11:01:53 +00:00
)
func TestPubsub(t *testing.T) {
service := NewService()
sub := service.Subscribe("a")
service.Publish("a", 1)
select {
case v := <-sub.Wait():
if v != 1 {
t.Error("expected subscribed value 1, but got ", v)
}
default:
t.Fail()
}
sub.Close()
service.Publish("a", 2)
select {
case <-sub.Wait():
t.Fail()
default:
}
service.Cleanup()
}