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