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.
 

34 lines
662 B

package dispatcher
import (
"testing"
"time"
)
func TestNewDispatcher(t *testing.T) {
d := NewDispatcher()
if d.subscribers == nil {
t.Error("Dispatcher subscribers is nil")
}
if d.subscribersMu == nil {
t.Error("Dispatcher subscribersMu is nil")
}
}
func TestAddSubscriber(t *testing.T) {
d := NewDispatcher()
d.AddSubscriber()
if len(d.subscribers) != 1 {
t.Error("Dispatcher subscribers length is not 1")
}
}
func TestCloseSubscriber(t *testing.T) {
d := NewDispatcher()
_, closeCh := d.AddSubscriber()
close(closeCh)
time.Sleep(time.Millisecond)
if len(d.subscribers) != 0 {
t.Error("Dispatcher subscribers length is not 0")
}
}