2017-04-12 20:31:11 +00:00
|
|
|
package mux_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "v2ray.com/core/app/proxyman/mux"
|
|
|
|
"v2ray.com/core/testing/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionManagerAdd(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
m := NewSessionManager()
|
|
|
|
|
2017-04-13 18:14:07 +00:00
|
|
|
s := m.Allocate()
|
2017-04-12 20:31:11 +00:00
|
|
|
assert.Uint16(s.ID).Equals(1)
|
|
|
|
|
2017-04-13 18:14:07 +00:00
|
|
|
s = m.Allocate()
|
2017-04-12 20:31:11 +00:00
|
|
|
assert.Uint16(s.ID).Equals(2)
|
|
|
|
|
|
|
|
s = &Session{
|
|
|
|
ID: 4,
|
|
|
|
}
|
|
|
|
m.Add(s)
|
|
|
|
assert.Uint16(s.ID).Equals(4)
|
|
|
|
}
|
2017-04-19 10:36:04 +00:00
|
|
|
|
|
|
|
func TestSessionManagerClose(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
m := NewSessionManager()
|
|
|
|
s := m.Allocate()
|
|
|
|
|
|
|
|
assert.Bool(m.CloseIfNoSession()).IsFalse()
|
|
|
|
m.Remove(s.ID)
|
|
|
|
assert.Bool(m.CloseIfNoSession()).IsTrue()
|
|
|
|
}
|