You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngs/group_test.go

42 lines
623 B
Go

package ngs
import (
"git.noahlan.cn/northlan/ngs/session"
"math/rand"
"testing"
)
func TestChannel_Add(t *testing.T) {
c := NewGroup("test_add")
var paraCount = 100
w := make(chan bool, paraCount)
for i := 0; i < paraCount; i++ {
go func(id int) {
s := session.New(nil)
s.Bind(int64(id + 1))
c.Add(s)
w <- true
}(i)
}
for i := 0; i < paraCount; i++ {
<-w
}
if c.Count() != paraCount {
t.Fatalf("count expect: %d, got: %d", paraCount, c.Count())
}
n := rand.Int63n(int64(paraCount)) + 1
if !c.Contains(n) {
t.Fail()
}
// leave
c.LeaveAll()
if c.Count() != 0 {
t.Fail()
}
}