1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/common/signal/pubsub/pubsub_test.go
2022-01-02 15:16:23 +00:00

35 lines
465 B
Go

package pubsub_test
import (
"testing"
. "github.com/v2fly/v2ray-core/v5/common/signal/pubsub"
)
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()
}