2017-04-12 16:31:11 -04:00
|
|
|
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"
|
2017-04-12 16:31:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSessionManagerAdd(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2017-04-12 16:31:11 -04:00
|
|
|
|
|
|
|
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-12 16:31:11 -04:00
|
|
|
|
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)
|
2017-04-12 16:31:11 -04:00
|
|
|
|
|
|
|
s = &Session{
|
|
|
|
ID: 4,
|
|
|
|
}
|
|
|
|
m.Add(s)
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(s.ID, Equals, uint16(4))
|
2017-04-12 16:31:11 -04:00
|
|
|
}
|
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
|
|
|
}
|