A pooled implementation of Twitch PubSub
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.

74 lines
1.6 KiB

package twpubsub
import (
"fmt"
"testing"
)
func init() {
isTesting = true
}
func TestPool(t *testing.T) {
p := NewPool(nil)
for i := 0; i < 2; i++ {
if i == 0 {
p.AddTopics([]string{"a"})
} else {
p.AddTopics([]string{
"a", "a", "a", "a", "a",
"a", "a", "a", "a", "a",
"a", "a", "a", "a", "a",
"a", "a", "a", "a", "a",
"a", "a", "a", "a", "a",
"a", "a", "a", "a", "a",
"a", "a", "a", "a", "a",
})
}
if p.cons.Len() != 1 {
t.Errorf("Expect cons.Len = 1, not %v", p.cons.Len())
}
f := p.cons.Front().Value.(*WS)
t.Logf("Topics: %#v", f.topics)
if len(f.topics) != 1 {
t.Errorf("Expected f.topics = 1, not %v", len(f.topics))
}
}
var topics []string
for i := 0; i < 52; i++ {
topics = append(topics, fmt.Sprint("topic.", i))
}
p.AddTopics(topics)
if p.cons.Len() != 2 {
t.Errorf("Expect cons.Len = 2, not %v", p.cons.Len())
}
if l := len(p.cons.Back().Value.(*WS).topics); l != 50 {
t.Errorf("Expected b.topics = 50, not %v", l)
}
if l := len(p.cons.Front().Value.(*WS).topics); l != 3 {
t.Errorf("Expected f.topics = 3, not %v", l)
}
p.RemoveTopics(topics[:10])
if p.cons.Len() != 2 {
t.Errorf("Expect cons.Len = 2, not %v", p.cons.Len())
}
if l := len(p.cons.Back().Value.(*WS).topics); l != 40 {
t.Errorf("Expected b.topics = 40, not %v", l)
}
if l := len(p.cons.Front().Value.(*WS).topics); l != 3 {
t.Errorf("Expected f.topics = 3, not %v", l)
}
p.RemoveTopics(topics)
if p.cons.Len() != 1 {
t.Errorf("Expect cons.Len = 1, not %v", p.cons.Len())
}
if l := len(p.cons.Front().Value.(*WS).topics); l != 1 {
t.Errorf("Expected f.topics = 1, not %v", l)
}
}