1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00
v2fly/common/mux/session_test.go

52 lines
754 B
Go
Raw Normal View History

package mux_test
import (
"testing"
2021-02-16 15:31:50 -05:00
. "github.com/v2fly/v2ray-core/v4/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
}