1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 10:26:10 -04:00
v2fly/common/signal/pubsub/pubsub_test.go

35 lines
465 B
Go
Raw Normal View History

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