connmgr_test.go
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package websocket
import (
"github.com/gorilla/websocket"
"testing"
)
func TestNewMemoryConnmgr(t *testing.T){
connmgr :=NewMemoryConnmgr()
num:=100
var listConn []*WebsocketConnection
for i:=0;i<num;i++{
listConn = append(listConn,&WebsocketConnection{
Uid:int64(i),
AppId:1,
Conn:&websocket.Conn{},
})
}
for i:=range listConn{
connmgr.Put(listConn[i],listConn[i])
}
if connmgr.Clients.Size() !=num && connmgr.Connections.Size()!=num{
t.Fatal("size error :",connmgr.Clients.Size(),connmgr.Connections.Size())
}
for i:=range listConn{
connmgr.Remove(listConn[i])
}
if connmgr.Clients.Size() !=0 && connmgr.Connections.Size()!=0{
t.Fatal("size error :",connmgr.Clients.Size(),connmgr.Connections.Size())
}
}
func BenchmarkNewMemoryConnmgr(b *testing.B) {
connmgr :=NewMemoryConnmgr()
var listConn []*WebsocketConnection
for i:=0;i<b.N;i++{
listConn = append(listConn,&WebsocketConnection{
Uid:int64(i),
AppId:1,
Conn:&websocket.Conn{},
})
}
b.ResetTimer()
for i:=0;i<b.N;i++{
connmgr.Put(listConn[i],listConn[i])
}
for i:=0;i<b.N;i++{
connmgr.Remove(listConn[i])
}
if connmgr.Clients.Size() !=0 && connmgr.Connections.Size()!=0{
b.Fatal("size error :",connmgr.Clients.Size(),connmgr.Connections.Size())
}
}