2017-04-12 20:31:11 +00:00
|
|
|
package mux_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "v2ray.com/core/app/proxyman/mux"
|
2017-10-24 14:15:35 +00:00
|
|
|
. "v2ray.com/ext/assert"
|
2017-04-12 20:31:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionManagerAdd(t *testing.T) {
|
2017-10-24 14:15:35 +00:00
|
|
|
assert := With(t)
|
2017-04-12 20:31:11 +00:00
|
|
|
|
|
|
|
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-12 20:31:11 +00:00
|
|
|
|
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)
|
2017-04-12 20:31:11 +00:00
|
|
|
|
|
|
|
s = &Session{
|
|
|
|
ID: 4,
|
|
|
|
}
|
|
|
|
m.Add(s)
|
2017-10-24 14:15:35 +00:00
|
|
|
assert(s.ID, Equals, uint16(4))
|
2017-04-12 20:31:11 +00:00
|
|
|
}
|
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
|
|
|
}
|