mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
451 B
35 lines
451 B
package pubsub_test |
|
|
|
import ( |
|
"testing" |
|
|
|
. "v2ray.com/core/common/signal/pubsub" |
|
. "v2ray.com/ext/assert" |
|
) |
|
|
|
func TestPubsub(t *testing.T) { |
|
assert := With(t) |
|
|
|
service := NewService() |
|
|
|
sub := service.Subscribe("a") |
|
service.Publish("a", 1) |
|
|
|
select { |
|
case v := <-sub.Wait(): |
|
assert(v.(int), Equals, 1) |
|
default: |
|
t.Fail() |
|
} |
|
|
|
sub.Close() |
|
service.Publish("a", 2) |
|
|
|
select { |
|
case <-sub.Wait(): |
|
t.Fail() |
|
default: |
|
} |
|
|
|
service.Cleanup() |
|
}
|
|
|