1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

remove port testing

This commit is contained in:
v2ray 2016-08-15 22:12:11 +02:00
parent 338dc1ebb6
commit a5a70afdb8
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
9 changed files with 17 additions and 42 deletions

View File

@ -1,10 +0,0 @@
package testing
import (
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
)
func PickPort() v2net.Port {
return v2net.Port(30000 + dice.Roll(20000))
}

View File

@ -8,8 +8,8 @@ import (
"github.com/v2ray/v2ray-core/app/dispatcher"
dispatchers "github.com/v2ray/v2ray-core/app/dispatcher/impl"
"github.com/v2ray/v2ray-core/app/proxyman"
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
"github.com/v2ray/v2ray-core/proxy"
. "github.com/v2ray/v2ray-core/proxy/dokodemo"
"github.com/v2ray/v2ray-core/proxy/freedom"
@ -23,7 +23,6 @@ func TestDokodemoTCP(t *testing.T) {
assert := assert.On(t)
tcpServer := &tcp.Server{
Port: v2nettesting.PickPort(),
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
@ -53,7 +52,7 @@ func TestDokodemoTCP(t *testing.T) {
data2Send := "Data to be sent to remote."
port := v2nettesting.PickPort()
port := v2net.Port(dice.Roll(20000) + 10000)
dokodemo := NewDokodemoDoor(&Config{
Address: v2net.LocalHostIP,
Port: tcpServer.Port,
@ -95,7 +94,6 @@ func TestDokodemoUDP(t *testing.T) {
assert := assert.On(t)
udpServer := &udp.Server{
Port: v2nettesting.PickPort(),
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
@ -124,7 +122,7 @@ func TestDokodemoUDP(t *testing.T) {
data2Send := "Data to be sent to remote."
port := v2nettesting.PickPort()
port := v2net.Port(dice.Roll(20000) + 10000)
dokodemo := NewDokodemoDoor(&Config{
Address: v2net.LocalHostIP,
Port: udpServer.Port,

View File

@ -13,7 +13,6 @@ import (
"github.com/v2ray/v2ray-core/app/router/rules"
"github.com/v2ray/v2ray-core/common/alloc"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
"github.com/v2ray/v2ray-core/proxy"
. "github.com/v2ray/v2ray-core/proxy/freedom"
"github.com/v2ray/v2ray-core/testing/assert"
@ -24,10 +23,8 @@ import (
func TestSinglePacket(t *testing.T) {
assert := assert.On(t)
port := v2nettesting.PickPort()
tcpServer := &tcp.Server{
Port: port,
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)

View File

@ -7,8 +7,8 @@ import (
"testing"
testdispatcher "github.com/v2ray/v2ray-core/app/dispatcher/testing"
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
"github.com/v2ray/v2ray-core/proxy"
. "github.com/v2ray/v2ray-core/proxy/http"
"github.com/v2ray/v2ray-core/testing/assert"
@ -56,7 +56,7 @@ func TestNormalGetRequest(t *testing.T) {
testPacketDispatcher := testdispatcher.NewTestPacketDispatcher(nil)
port := v2nettesting.PickPort()
port := v2net.Port(dice.Roll(20000) + 10000)
httpProxy := NewServer(
&Config{},
testPacketDispatcher,

View File

@ -5,7 +5,6 @@ import (
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
"github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp"
"github.com/v2ray/v2ray-core/testing/servers/udp"
@ -14,9 +13,7 @@ import (
func TestTCPConnection(t *testing.T) {
assert := assert.On(t)
targetPort := v2nettesting.PickPort()
tcpServer := &tcp.Server{
Port: targetPort,
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
@ -49,7 +46,7 @@ func TestTCPConnection(t *testing.T) {
assert.Error(err).IsNil()
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
connectRequest := socks5Request(byte(1), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), targetPort))
connectRequest := socks5Request(byte(1), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), tcpServer.Port))
nBytes, err = conn.Write(connectRequest)
assert.Int(nBytes).Equals(len(connectRequest))
assert.Error(err).IsNil()
@ -89,9 +86,7 @@ func TestTCPConnection(t *testing.T) {
func TestTCPBind(t *testing.T) {
assert := assert.On(t)
targetPort := v2nettesting.PickPort()
tcpServer := &tcp.Server{
Port: targetPort,
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
@ -122,7 +117,7 @@ func TestTCPBind(t *testing.T) {
assert.Error(err).IsNil()
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
connectRequest := socks5Request(byte(2), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), targetPort))
connectRequest := socks5Request(byte(2), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), tcpServer.Port))
nBytes, err = conn.Write(connectRequest)
assert.Int(nBytes).Equals(len(connectRequest))
assert.Error(err).IsNil()
@ -140,9 +135,7 @@ func TestTCPBind(t *testing.T) {
func TestUDPAssociate(t *testing.T) {
assert := assert.On(t)
targetPort := v2nettesting.PickPort()
udpServer := &udp.Server{
Port: targetPort,
MsgProcessor: func(data []byte) []byte {
buffer := make([]byte, 0, 2048)
buffer = append(buffer, []byte("Processed: ")...)
@ -173,7 +166,7 @@ func TestUDPAssociate(t *testing.T) {
assert.Error(err).IsNil()
assert.Bytes(authResponse[:nBytes]).Equals([]byte{socks5Version, 0})
connectRequest := socks5Request(byte(3), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), targetPort))
connectRequest := socks5Request(byte(3), v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), udpServer.Port))
nBytes, err = conn.Write(connectRequest)
assert.Int(nBytes).Equals(len(connectRequest))
assert.Error(err).IsNil()
@ -191,7 +184,7 @@ func TestUDPAssociate(t *testing.T) {
for i := 0; i < 100; i++ {
udpPayload := "UDP request to udp server."
udpRequest := socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, targetPort), []byte(udpPayload))
udpRequest := socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, udpServer.Port), []byte(udpPayload))
nBytes, err = udpConn.Write(udpRequest)
assert.Int(nBytes).Equals(len(udpRequest))
@ -201,7 +194,7 @@ func TestUDPAssociate(t *testing.T) {
nBytes, err = udpConn.Read(udpResponse)
assert.Error(err).IsNil()
assert.Bytes(udpResponse[:nBytes]).Equals(
socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, targetPort), []byte("Processed: UDP request to udp server.")))
socks5UDPRequest(v2net.UDPDestination(v2net.LocalHostIP, udpServer.Port), []byte("Processed: UDP request to udp server.")))
}
udpConn.Close()

View File

@ -23,6 +23,7 @@ func (server *Server) Start() (v2net.Destination, error) {
if err != nil {
return nil, err
}
server.Port = v2net.Port(listener.Addr().(*net.TCPAddr).Port)
server.listener = listener
go server.acceptConnections(listener)
localAddr := listener.Addr().(*net.TCPAddr)

View File

@ -23,6 +23,7 @@ func (server *Server) Start() (v2net.Destination, error) {
if err != nil {
return nil, err
}
server.Port = v2net.Port(conn.LocalAddr().(*net.UDPAddr).Port)
server.conn = conn
go server.handleConnection(conn)
localAddr := conn.LocalAddr().(*net.UDPAddr)

View File

@ -4,7 +4,6 @@ import (
"testing"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
"github.com/v2ray/v2ray-core/testing/assert"
"github.com/v2ray/v2ray-core/testing/servers/tcp"
. "github.com/v2ray/v2ray-core/transport/internet"
@ -13,9 +12,7 @@ import (
func TestDialDomain(t *testing.T) {
assert := assert.On(t)
server := &tcp.Server{
Port: v2nettesting.PickPort(),
}
server := &tcp.Server{}
dest, err := server.Start()
assert.Error(err).IsNil()
defer server.Close()
@ -29,9 +26,7 @@ func TestDialDomain(t *testing.T) {
func TestDialWithLocalAddr(t *testing.T) {
assert := assert.On(t)
server := &tcp.Server{
Port: v2nettesting.PickPort(),
}
server := &tcp.Server{}
dest, err := server.Start()
assert.Error(err).IsNil()
defer server.Close()

View File

@ -3,12 +3,12 @@ package kcp_test
import (
"crypto/rand"
"io"
"net"
"sync"
"testing"
"time"
v2net "github.com/v2ray/v2ray-core/common/net"
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
"github.com/v2ray/v2ray-core/testing/assert"
. "github.com/v2ray/v2ray-core/transport/internet/kcp"
)
@ -16,9 +16,9 @@ import (
func TestDialAndListen(t *testing.T) {
assert := assert.On(t)
port := v2nettesting.PickPort()
listerner, err := NewListener(v2net.LocalHostIP, port)
listerner, err := NewListener(v2net.LocalHostIP, v2net.Port(0))
assert.Error(err).IsNil()
port := v2net.Port(listerner.Addr().(*net.UDPAddr).Port)
go func() {
for {