Explorar o código

concurrent connection in h2

Darien Raymond %!s(int64=7) %!d(string=hai) anos
pai
achega
2e7944a9eb
Modificáronse 1 ficheiros con 25 adicións e 15 borrados
  1. 25 15
      testing/scenarios/tls_test.go

+ 25 - 15
testing/scenarios/tls_test.go

@@ -2,6 +2,7 @@ package scenarios
 
 import (
 	"crypto/rand"
+	"sync"
 	"testing"
 	"time"
 
@@ -495,21 +496,30 @@ func TestHTTP2(t *testing.T) {
 	servers, err := InitializeServerConfigs(serverConfig, clientConfig)
 	assert(err, IsNil)
 
-	conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
-		IP:   []byte{127, 0, 0, 1},
-		Port: int(clientPort),
-	})
-	assert(err, IsNil)
-
-	payload := make([]byte, 10240*1024)
-	rand.Read(payload)
-	nBytes, err := conn.Write([]byte(payload))
-	assert(err, IsNil)
-	assert(nBytes, Equals, len(payload))
-
-	response := readFrom(conn, time.Second*20, len(payload))
-	assert(response, Equals, xor([]byte(payload)))
-	assert(conn.Close(), IsNil)
+	var wg sync.WaitGroup
+	for i := 0; i < 10; i++ {
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+
+			conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
+				IP:   []byte{127, 0, 0, 1},
+				Port: int(clientPort),
+			})
+			assert(err, IsNil)
+
+			payload := make([]byte, 10240*1024)
+			rand.Read(payload)
+			nBytes, err := conn.Write([]byte(payload))
+			assert(err, IsNil)
+			assert(nBytes, Equals, len(payload))
+
+			response := readFrom(conn, time.Second*20, len(payload))
+			assert(response, Equals, xor([]byte(payload)))
+			assert(conn.Close(), IsNil)
+		}()
+	}
+	wg.Wait()
 
 	CloseAllServers(servers)
 }