1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-19 19:06:43 -05:00
v2fly/common/mux/session_test.go

40 lines
631 B
Go
Raw Normal View History

package mux_test
import (
"testing"
2018-10-23 06:21:12 -04:00
. "v2ray.com/core/common/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
}