1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-28 18:25:23 +00:00
v2fly/common/mux/session_test.go

52 lines
754 B
Go
Raw Normal View History

package mux_test
import (
"testing"
2021-02-16 20:31:50 +00:00
. "github.com/v2fly/v2ray-core/v4/common/mux"
)
func TestSessionManagerAdd(t *testing.T) {
m := NewSessionManager()
2017-04-13 18:14:07 +00:00
s := m.Allocate()
2019-02-10 14:02:28 +00:00
if s.ID != 1 {
t.Error("id: ", s.ID)
}
if m.Size() != 1 {
t.Error("size: ", m.Size())
}
2017-04-13 18:14:07 +00:00
s = m.Allocate()
2019-02-10 14:02:28 +00: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 14:02:28 +00:00
if s.ID != 4 {
t.Error("id: ", s.ID)
}
if m.Size() != 3 {
t.Error("size: ", m.Size())
}
}
2017-04-19 10:36:04 +00:00
func TestSessionManagerClose(t *testing.T) {
m := NewSessionManager()
s := m.Allocate()
2019-02-10 14:02:28 +00:00
if m.CloseIfNoSession() {
t.Error("able to close")
}
2017-04-19 10:36:04 +00:00
m.Remove(s.ID)
2019-02-10 14:02:28 +00:00
if !m.CloseIfNoSession() {
t.Error("not able to close")
}
2017-04-19 10:36:04 +00:00
}