mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-10-14 04:54:03 -04:00
remove dep of assert lib
This commit is contained in:
@@ -6,31 +6,36 @@ import (
|
||||
|
||||
"v2ray.com/core/common/net"
|
||||
. "v2ray.com/core/common/protocol"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestServerList(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
list := NewServerList()
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(1)), AlwaysValid()))
|
||||
assert(list.Size(), Equals, uint32(1))
|
||||
if list.Size() != 1 {
|
||||
t.Error("list size: ", list.Size())
|
||||
}
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
|
||||
assert(list.Size(), Equals, uint32(2))
|
||||
if list.Size() != 2 {
|
||||
t.Error("list.size: ", list.Size())
|
||||
}
|
||||
|
||||
server := list.GetServer(1)
|
||||
assert(server.Destination().Port, Equals, net.Port(2))
|
||||
if server.Destination().Port != 2 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
server = list.GetServer(1)
|
||||
assert(server, IsNil)
|
||||
if server != nil {
|
||||
t.Error("server: ", server)
|
||||
}
|
||||
|
||||
server = list.GetServer(0)
|
||||
assert(server.Destination().Port, Equals, net.Port(1))
|
||||
if server.Destination().Port != 1 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerPicker(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
list := NewServerList()
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(1)), AlwaysValid()))
|
||||
list.AddServer(NewServerSpec(net.TCPDestination(net.LocalHostIP, net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
|
||||
@@ -38,17 +43,29 @@ func TestServerPicker(t *testing.T) {
|
||||
|
||||
picker := NewRoundRobinServerPicker(list)
|
||||
server := picker.PickServer()
|
||||
assert(server.Destination().Port, Equals, net.Port(1))
|
||||
if server.Destination().Port != 1 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
server = picker.PickServer()
|
||||
assert(server.Destination().Port, Equals, net.Port(2))
|
||||
if server.Destination().Port != 2 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
server = picker.PickServer()
|
||||
assert(server.Destination().Port, Equals, net.Port(3))
|
||||
if server.Destination().Port != 3 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
server = picker.PickServer()
|
||||
assert(server.Destination().Port, Equals, net.Port(1))
|
||||
if server.Destination().Port != 1 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
server = picker.PickServer()
|
||||
assert(server.Destination().Port, Equals, net.Port(1))
|
||||
if server.Destination().Port != 1 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
server = picker.PickServer()
|
||||
assert(server.Destination().Port, Equals, net.Port(1))
|
||||
if server.Destination().Port != 1 {
|
||||
t.Error("server: ", server.Destination())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user