1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

fix broken test

This commit is contained in:
Darien Raymond 2019-01-07 11:37:06 +01:00
parent d26700a2fe
commit 5f53530cc1
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 22 additions and 15 deletions

View File

@ -32,7 +32,7 @@ func TestParseString(t *testing.T) {
uuid, err := ParseString(str) uuid, err := ParseString(str)
common.Must(err) common.Must(err)
if r := cmp.Diff(expectedBytes, uuid.Bytes); r != "" { if r := cmp.Diff(expectedBytes, uuid.Bytes()); r != "" {
t.Fatal(r) t.Fatal(r)
} }

View File

@ -2,10 +2,11 @@ package scenarios
import ( import (
"crypto/rand" "crypto/rand"
"sync"
"testing" "testing"
"time" "time"
"golang.org/x/sync/errgroup"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"v2ray.com/core" "v2ray.com/core"
"v2ray.com/core/app/log" "v2ray.com/core/app/log"
@ -14,6 +15,7 @@ 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"
@ -189,36 +191,41 @@ func TestReverseProxy(t *testing.T) {
defer CloseAllServers(servers) defer CloseAllServers(servers)
var wg sync.WaitGroup var errg errgroup.Group
wg.Add(32)
for i := 0; i < 32; i++ { for i := 0; i < 32; i++ {
go func() { errg.Go(func() error {
defer wg.Done()
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
IP: []byte{127, 0, 0, 1}, IP: []byte{127, 0, 0, 1},
Port: int(externalPort), Port: int(externalPort),
}) })
common.Must(err) if err != nil {
return err
}
defer conn.Close() defer conn.Close()
payload := make([]byte, 10240*1024) payload := make([]byte, 10240*1024)
rand.Read(payload) rand.Read(payload)
nBytes, err := conn.Write([]byte(payload)) nBytes, err := conn.Write([]byte(payload))
common.Must(err) if err != nil {
return err
}
if nBytes != len(payload) { if nBytes != len(payload) {
t.Error("only part of payload is written: ", nBytes) return errors.New("only part of payload is written: ", nBytes)
} }
response := readFrom(conn, time.Second*20, 10240*1024) response := readFrom(conn, time.Second*20, 10240*1024)
if r := cmp.Diff(response, xor([]byte(payload))); r != "" { if r := cmp.Diff(response, xor(payload)); r != "" {
t.Error(r) return errors.New(r)
} }
}() return nil
})
}
if err := errg.Wait(); err != nil {
t.Fatal(err)
} }
wg.Wait()
} }
func TestReverseProxyLongRunning(t *testing.T) { func TestReverseProxyLongRunning(t *testing.T) {
@ -428,7 +435,7 @@ func TestReverseProxyLongRunning(t *testing.T) {
} }
response := readFrom(conn, time.Second*5, 1024) response := readFrom(conn, time.Second*5, 1024)
if r := cmp.Diff(response, xor([]byte(payload))); r != "" { if r := cmp.Diff(response, xor(payload)); r != "" {
t.Error(r) t.Error(r)
} }