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

40 lines
631 B
Go
Raw Normal View History

package mux_test
import (
"testing"
2018-10-23 10:21:12 +00:00
. "v2ray.com/core/common/mux"
2017-10-24 14:15:35 +00:00
. "v2ray.com/ext/assert"
)
func TestSessionManagerAdd(t *testing.T) {
2017-10-24 14:15:35 +00:00
assert := With(t)
m := NewSessionManager()
2017-04-13 18:14:07 +00:00
s := m.Allocate()
2017-10-24 14:15:35 +00:00
assert(s.ID, Equals, uint16(1))
assert(m.Size(), Equals, 1)
2017-04-13 18:14:07 +00:00
s = m.Allocate()
2017-10-24 14:15:35 +00:00
assert(s.ID, Equals, uint16(2))
assert(m.Size(), Equals, 2)
s = &Session{
ID: 4,
}
m.Add(s)
2017-10-24 14:15:35 +00:00
assert(s.ID, Equals, uint16(4))
}
2017-04-19 10:36:04 +00:00
func TestSessionManagerClose(t *testing.T) {
2017-10-24 14:15:35 +00:00
assert := With(t)
2017-04-19 10:36:04 +00:00
m := NewSessionManager()
s := m.Allocate()
2017-10-24 14:15:35 +00:00
assert(m.CloseIfNoSession(), IsFalse)
2017-04-19 10:36:04 +00:00
m.Remove(s.ID)
2017-10-24 14:15:35 +00:00
assert(m.CloseIfNoSession(), IsTrue)
2017-04-19 10:36:04 +00:00
}