mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
631 B
40 lines
631 B
package mux_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "v2ray.com/core/common/mux"
|
|
. "v2ray.com/ext/assert"
|
|
)
|
|
|
|
func TestSessionManagerAdd(t *testing.T) {
|
|
assert := With(t)
|
|
|
|
m := NewSessionManager()
|
|
|
|
s := m.Allocate()
|
|
assert(s.ID, Equals, uint16(1))
|
|
assert(m.Size(), Equals, 1)
|
|
|
|
s = m.Allocate()
|
|
assert(s.ID, Equals, uint16(2))
|
|
assert(m.Size(), Equals, 2)
|
|
|
|
s = &Session{
|
|
ID: 4,
|
|
}
|
|
m.Add(s)
|
|
assert(s.ID, Equals, uint16(4))
|
|
}
|
|
|
|
func TestSessionManagerClose(t *testing.T) {
|
|
assert := With(t)
|
|
|
|
m := NewSessionManager()
|
|
s := m.Allocate()
|
|
|
|
assert(m.CloseIfNoSession(), IsFalse)
|
|
m.Remove(s.ID)
|
|
assert(m.CloseIfNoSession(), IsTrue)
|
|
}
|