From a49816ae469260ced83889047783c5f21642ba83 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 3 Apr 2017 23:43:45 +0200 Subject: [PATCH] more complicated mux test --- testing/scenarios/vmess_test.go | 43 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/testing/scenarios/vmess_test.go b/testing/scenarios/vmess_test.go index 3904fc12..ea67393f 100644 --- a/testing/scenarios/vmess_test.go +++ b/testing/scenarios/vmess_test.go @@ -876,30 +876,33 @@ func TestVMessGCMMux(t *testing.T) { assert.Error(InitializeServerConfig(serverConfig)).IsNil() assert.Error(InitializeServerConfig(clientConfig)).IsNil() - var wg sync.WaitGroup - wg.Add(100) - for i := 0; i < 100; i++ { - go func() { - conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ - IP: []byte{127, 0, 0, 1}, - Port: int(clientPort), - }) - assert.Error(err).IsNil() + for range "abcd" { + var wg sync.WaitGroup + const nConnection = 100 + wg.Add(nConnection) + for i := 0; i < nConnection; i++ { + go func() { + conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{ + IP: []byte{127, 0, 0, 1}, + Port: int(clientPort), + }) + assert.Error(err).IsNil() - payload := make([]byte, 10240) - rand.Read(payload) + payload := make([]byte, 10240) + rand.Read(payload) - nBytes, err := conn.Write([]byte(payload)) - assert.Error(err).IsNil() - assert.Int(nBytes).Equals(len(payload)) + nBytes, err := conn.Write([]byte(payload)) + assert.Error(err).IsNil() + assert.Int(nBytes).Equals(len(payload)) - response := readFrom(conn, time.Second*10, 10240) - assert.Bytes(response).Equals(xor([]byte(payload))) - assert.Error(conn.Close()).IsNil() - wg.Done() - }() + response := readFrom(conn, time.Second*10, 10240) + assert.Bytes(response).Equals(xor([]byte(payload))) + assert.Error(conn.Close()).IsNil() + wg.Done() + }() + } + wg.Wait() } - wg.Wait() CloseAllServers() }