2020-11-25 14:01:53 +03:00
|
|
|
package mux_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-12-04 04:36:16 +03:00
|
|
|
. "github.com/xtls/xray-core/common/mux"
|
2020-11-25 14:01:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionManagerAdd(t *testing.T) {
|
|
|
|
m := NewSessionManager()
|
|
|
|
|
|
|
|
s := m.Allocate()
|
|
|
|
if s.ID != 1 {
|
|
|
|
t.Error("id: ", s.ID)
|
|
|
|
}
|
|
|
|
if m.Size() != 1 {
|
|
|
|
t.Error("size: ", m.Size())
|
|
|
|
}
|
|
|
|
|
|
|
|
s = m.Allocate()
|
|
|
|
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)
|
|
|
|
if s.ID != 4 {
|
|
|
|
t.Error("id: ", s.ID)
|
|
|
|
}
|
|
|
|
if m.Size() != 3 {
|
|
|
|
t.Error("size: ", m.Size())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSessionManagerClose(t *testing.T) {
|
|
|
|
m := NewSessionManager()
|
|
|
|
s := m.Allocate()
|
|
|
|
|
|
|
|
if m.CloseIfNoSession() {
|
|
|
|
t.Error("able to close")
|
|
|
|
}
|
2023-04-06 13:21:35 +03:00
|
|
|
m.Remove(false, s.ID)
|
2020-11-25 14:01:53 +03:00
|
|
|
if !m.CloseIfNoSession() {
|
|
|
|
t.Error("not able to close")
|
|
|
|
}
|
|
|
|
}
|