mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-05 06:33:02 +00:00
35 lines
463 B
Go
35 lines
463 B
Go
|
package pubsub_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
. "github.com/xtls/xray-core/v1/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()
|
||
|
}
|