1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-03 16:57:38 -05:00
v2fly/common/mux/session_test.go

52 lines
738 B
Go
Raw Normal View History

package mux_test
import (
"testing"
2018-10-23 06:21:12 -04:00
. "v2ray.com/core/common/mux"
)
func TestSessionManagerAdd(t *testing.T) {
m := NewSessionManager()
2017-04-13 14:14:07 -04:00
s := m.Allocate()
2019-02-10 09:02:28 -05:00
if s.ID != 1 {
t.Error("id: ", s.ID)
}
if m.Size() != 1 {
t.Error("size: ", m.Size())
}
2017-04-13 14:14:07 -04:00
s = m.Allocate()
2019-02-10 09:02:28 -05:00
if s.ID != 2 {
t.Error("id: ", s.ID)
}
if m.Size() != 2 {
t.Error("size: ", m.Size())
}
s = &Session{
ID: 4,
}
m.Add(s)
2019-02-10 09:02:28 -05:00
if s.ID != 4 {
t.Error("id: ", s.ID)
}
if m.Size() != 3 {
t.Error("size: ", m.Size())
}
}
2017-04-19 06:36:04 -04:00
func TestSessionManagerClose(t *testing.T) {
m := NewSessionManager()
s := m.Allocate()
2019-02-10 09:02:28 -05:00
if m.CloseIfNoSession() {
t.Error("able to close")
}
2017-04-19 06:36:04 -04:00
m.Remove(s.ID)
2019-02-10 09:02:28 -05:00
if !m.CloseIfNoSession() {
t.Error("not able to close")
}
2017-04-19 06:36:04 -04:00
}