mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-24 08:02:18 +02:00
a0d008e071
* Move cncd/{logging,pubsub,queue}/ to server/{logging,pubsub,queue}/ * Update REAMDEs and include history Co-authored-by: Anbraten <anton@ju60.de> Co-authored-by: Anbraten <anton@ju60.de>
43 lines
865 B
Go
43 lines
865 B
Go
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("Exepect subscription registered with topic on subscribe")
|
|
}
|
|
}
|
|
|
|
func TestTopicUnsubscribe(t *testing.T) {
|
|
sub := new(subscriber)
|
|
top := newTopic("foo")
|
|
top.subscribe(sub)
|
|
if _, ok := top.subs[sub]; !ok {
|
|
t.Errorf("Exepect subscription registered with topic on subscribe")
|
|
}
|
|
top.unsubscribe(sub)
|
|
if _, ok := top.subs[sub]; ok {
|
|
t.Errorf("Exepect subscription de-registered with topic on unsubscribe")
|
|
}
|
|
}
|
|
|
|
func TestTopicClose(t *testing.T) {
|
|
sub := new(subscriber)
|
|
top := newTopic("foo")
|
|
top.subscribe(sub)
|
|
go func() {
|
|
top.close()
|
|
}()
|
|
select {
|
|
case <-top.done:
|
|
case <-time.After(1 * time.Second):
|
|
t.Errorf("Expect subscription closed")
|
|
}
|
|
}
|