mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
631 B
40 lines
631 B
8 years ago
|
package mux_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
6 years ago
|
. "v2ray.com/core/common/mux"
|
||
7 years ago
|
. "v2ray.com/ext/assert"
|
||
8 years ago
|
)
|
||
|
|
||
|
func TestSessionManagerAdd(t *testing.T) {
|
||
7 years ago
|
assert := With(t)
|
||
8 years ago
|
|
||
|
m := NewSessionManager()
|
||
|
|
||
8 years ago
|
s := m.Allocate()
|
||
7 years ago
|
assert(s.ID, Equals, uint16(1))
|
||
|
assert(m.Size(), Equals, 1)
|
||
8 years ago
|
|
||
8 years ago
|
s = m.Allocate()
|
||
7 years ago
|
assert(s.ID, Equals, uint16(2))
|
||
|
assert(m.Size(), Equals, 2)
|
||
8 years ago
|
|
||
|
s = &Session{
|
||
|
ID: 4,
|
||
|
}
|
||
|
m.Add(s)
|
||
7 years ago
|
assert(s.ID, Equals, uint16(4))
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
func TestSessionManagerClose(t *testing.T) {
|
||
7 years ago
|
assert := With(t)
|
||
8 years ago
|
|
||
|
m := NewSessionManager()
|
||
|
s := m.Allocate()
|
||
|
|
||
7 years ago
|
assert(m.CloseIfNoSession(), IsFalse)
|
||
8 years ago
|
m.Remove(s.ID)
|
||
7 years ago
|
assert(m.CloseIfNoSession(), IsTrue)
|
||
8 years ago
|
}
|