1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-20 08:16:55 -05:00

update reverse test

This commit is contained in:
Darien Raymond 2019-01-08 23:43:24 +01:00
parent 5c37439dbb
commit 84bb0f13a5
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -1,13 +1,11 @@
package scenarios package scenarios
import ( import (
"crypto/rand"
"testing" "testing"
"time" "time"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"github.com/google/go-cmp/cmp"
"v2ray.com/core" "v2ray.com/core"
"v2ray.com/core/app/log" "v2ray.com/core/app/log"
"v2ray.com/core/app/policy" "v2ray.com/core/app/policy"
@ -15,7 +13,6 @@ import (
"v2ray.com/core/app/reverse" "v2ray.com/core/app/reverse"
"v2ray.com/core/app/router" "v2ray.com/core/app/router"
"v2ray.com/core/common" "v2ray.com/core/common"
"v2ray.com/core/common/errors"
clog "v2ray.com/core/common/log" clog "v2ray.com/core/common/log"
"v2ray.com/core/common/net" "v2ray.com/core/common/net"
"v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol"
@ -193,34 +190,7 @@ func TestReverseProxy(t *testing.T) {
var errg errgroup.Group var errg errgroup.Group
for i := 0; i < 32; i++ { for i := 0; i < 32; i++ {
errg.Go(func() error { errg.Go(testTCPConn(externalPort, 10240*1024, time.Second*20))
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1},
Port: int(externalPort),
})
if err != nil {
return err
}
defer conn.Close()
payload := make([]byte, 10240*1024)
rand.Read(payload)
nBytes, err := conn.Write([]byte(payload))
if err != nil {
return err
}
if nBytes != len(payload) {
return errors.New("only part of payload is written: ", nBytes)
}
response := readFrom(conn, time.Second*20, 10240*1024)
if r := cmp.Diff(response, xor(payload)); r != "" {
return errors.New(r)
}
return nil
})
} }
if err := errg.Wait(); err != nil { if err := errg.Wait(); err != nil {
@ -418,27 +388,8 @@ func TestReverseProxyLongRunning(t *testing.T) {
defer CloseAllServers(servers) defer CloseAllServers(servers)
for i := 0; i < 4096; i++ { for i := 0; i < 4096; i++ {
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ if err := testTCPConn(externalPort, 1024, time.Second*10)(); err != nil {
IP: []byte{127, 0, 0, 1}, t.Error(err)
Port: int(externalPort),
})
common.Must(err)
payload := make([]byte, 1024)
rand.Read(payload)
nBytes, err := conn.Write([]byte(payload))
common.Must(err)
if nBytes != len(payload) {
t.Error("only part of payload is written: ", nBytes)
} }
response := readFrom(conn, time.Second*5, 1024)
if r := cmp.Diff(response, xor(payload)); r != "" {
t.Error(r)
}
conn.Close()
} }
} }