woodpecker/server/pubsub/topic_test.go

43 lines
862 B
Go
Raw Normal View History

2019-04-06 13:44:04 +00:00
package pubsub
import (
"testing"
"time"
)
func TestTopicSubscribe(t *testing.T) {
sub := new(subscriber)
top := newTopic("foo")
top.subscribe(sub)
if _, ok := top.subs[sub]; !ok {
t.Errorf("Expect subscription registered with topic on subscribe")
2019-04-06 13:44:04 +00:00
}
}
func TestTopicUnsubscribe(t *testing.T) {
sub := new(subscriber)
top := newTopic("foo")
top.subscribe(sub)
if _, ok := top.subs[sub]; !ok {
t.Errorf("Expect subscription registered with topic on subscribe")
2019-04-06 13:44:04 +00:00
}
top.unsubscribe(sub)
if _, ok := top.subs[sub]; ok {
t.Errorf("Expect subscription de-registered with topic on unsubscribe")
2019-04-06 13:44:04 +00:00
}
}
func TestTopicClose(t *testing.T) {
sub := new(subscriber)
top := newTopic("foo")
top.subscribe(sub)
go func() {
top.close()
}()
select {
case <-top.done:
2020-05-18 14:46:13 +00:00
case <-time.After(1 * time.Second):
2019-04-06 13:44:04 +00:00
t.Errorf("Expect subscription closed")
}
}