1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-09 13:34:34 -04:00
v2fly/app/proxyman/mux/session_test.go

40 lines
637 B
Go
Raw Normal View History

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