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

35 lines
465 B
Go
Raw Permalink Normal View History

2018-07-01 12:38:40 +02:00
package pubsub_test
import (
"testing"
. "github.com/v2fly/v2ray-core/v5/common/signal/pubsub"
2018-07-01 12:38:40 +02:00
)
func TestPubsub(t *testing.T) {
service := NewService()
sub := service.Subscribe("a")
service.Publish("a", 1)
select {
case v := <-sub.Wait():
2019-01-31 20:57:01 +01:00
if v != 1 {
t.Error("expected subscribed value 1, but got ", v)
}
2018-07-01 12:38:40 +02:00
default:
t.Fail()
}
sub.Close()
service.Publish("a", 2)
select {
case <-sub.Wait():
t.Fail()
default:
}
2018-07-01 19:30:05 +02:00
service.Cleanup()
2018-07-01 12:38:40 +02:00
}