1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Explictly wait for server ready

This commit is contained in:
V2Ray 2015-09-24 18:08:55 +02:00
parent 9e4902d17a
commit d77fdbd719

View File

@ -3,6 +3,7 @@ package freedom
import ( import (
"io/ioutil" "io/ioutil"
"net" "net"
"sync"
"testing" "testing"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
@ -20,6 +21,9 @@ func TestSocksTcpConnect(t *testing.T) {
data2Send := "Data to be sent to remote" data2Send := "Data to be sent to remote"
data2Return := "Data to be returned to local" data2Return := "Data to be returned to local"
var serverReady sync.Mutex
serverReady.Lock()
go func() { go func() {
listener, err := net.ListenTCP("tcp", &net.TCPAddr{ listener, err := net.ListenTCP("tcp", &net.TCPAddr{
IP: []byte{0, 0, 0, 0}, IP: []byte{0, 0, 0, 0},
@ -27,6 +31,8 @@ func TestSocksTcpConnect(t *testing.T) {
Zone: "", Zone: "",
}) })
assert.Error(err).IsNil() assert.Error(err).IsNil()
serverReady.Unlock()
conn, err := listener.Accept() conn, err := listener.Accept()
assert.Error(err).IsNil() assert.Error(err).IsNil()
@ -65,6 +71,8 @@ func TestSocksTcpConnect(t *testing.T) {
socks5Client, err := proxy.SOCKS5("tcp", "127.0.0.1:38724", nil, proxy.Direct) socks5Client, err := proxy.SOCKS5("tcp", "127.0.0.1:38724", nil, proxy.Direct)
assert.Error(err).IsNil() assert.Error(err).IsNil()
serverReady.Lock()
targetServer := "127.0.0.1:48274" targetServer := "127.0.0.1:48274"
conn, err := socks5Client.Dial("tcp", targetServer) conn, err := socks5Client.Dial("tcp", targetServer)
assert.Error(err).IsNil() assert.Error(err).IsNil()