1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-30 05:56:54 -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)
common.Must(err)
if r := cmp.Diff(expectedBytes, uuid.Bytes); r != "" {
if r := cmp.Diff(expectedBytes, uuid.Bytes()); r != "" {
t.Fatal(r)
}

View File

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