forked from quic-go/quic-go
Simplify integration suite setup
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/h2quic"
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -46,7 +47,7 @@ var _ = Describe("Client tests", func() {
|
||||
})
|
||||
|
||||
It("downloads a hello", func() {
|
||||
resp, err := client.Get("https://quic.clemente.io:" + port + "/hello")
|
||||
resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/hello")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 3*time.Second))
|
||||
@@ -56,7 +57,7 @@ var _ = Describe("Client tests", func() {
|
||||
|
||||
It("downloads a small file", func() {
|
||||
dataMan.GenerateData(dataLen)
|
||||
resp, err := client.Get("https://quic.clemente.io:" + port + "/data")
|
||||
resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/data")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second))
|
||||
@@ -66,7 +67,7 @@ var _ = Describe("Client tests", func() {
|
||||
|
||||
It("downloads a large file", func() {
|
||||
dataMan.GenerateData(dataLongLen)
|
||||
resp, err := client.Get("https://quic.clemente.io:" + port + "/data")
|
||||
resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/data")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 20*time.Second))
|
||||
@@ -77,7 +78,7 @@ var _ = Describe("Client tests", func() {
|
||||
It("uploads a file", func() {
|
||||
dataMan.GenerateData(dataLen)
|
||||
data := bytes.NewReader(dataMan.GetData())
|
||||
resp, err := client.Post("https://quic.clemente.io:"+port+"/echo", "text/plain", data)
|
||||
resp, err := client.Post("https://quic.clemente.io:"+testserver.Port()+"/echo", "text/plain", data)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second))
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -25,7 +26,7 @@ var _ = Describe("Drop Proxy", func() {
|
||||
runDropTest := func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber) {
|
||||
var err error
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:0", quicproxy.Opts{
|
||||
RemoteAddr: "localhost:" + port,
|
||||
RemoteAddr: "localhost:" + testserver.Port(),
|
||||
DropPacket: dropCallback,
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||
@@ -31,7 +32,7 @@ var _ = Describe("Integration tests", func() {
|
||||
clientPath,
|
||||
"--quic-version="+strconv.Itoa(int(version)),
|
||||
"--host=127.0.0.1",
|
||||
"--port="+port,
|
||||
"--port="+testserver.Port(),
|
||||
"https://quic.clemente.io/hello",
|
||||
)
|
||||
session, err := Start(command, nil, GinkgoWriter)
|
||||
@@ -47,7 +48,7 @@ var _ = Describe("Integration tests", func() {
|
||||
clientPath,
|
||||
"--quic-version="+strconv.Itoa(int(version)),
|
||||
"--host=127.0.0.1",
|
||||
"--port="+port,
|
||||
"--port="+testserver.Port(),
|
||||
"--body=foo",
|
||||
"https://quic.clemente.io/echo",
|
||||
)
|
||||
@@ -64,7 +65,7 @@ var _ = Describe("Integration tests", func() {
|
||||
clientPath,
|
||||
"--quic-version="+strconv.Itoa(int(version)),
|
||||
"--host=127.0.0.1",
|
||||
"--port="+port,
|
||||
"--port="+testserver.Port(),
|
||||
"https://quic.clemente.io/data",
|
||||
)
|
||||
session, err := Start(command, nil, GinkgoWriter)
|
||||
@@ -85,7 +86,7 @@ var _ = Describe("Integration tests", func() {
|
||||
clientPath,
|
||||
"--quic-version="+strconv.Itoa(int(version)),
|
||||
"--host=127.0.0.1",
|
||||
"--port="+port,
|
||||
"--port="+testserver.Port(),
|
||||
"https://quic.clemente.io/data",
|
||||
)
|
||||
session, err := Start(command, nil, GinkgoWriter)
|
||||
|
||||
@@ -4,17 +4,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"strconv"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/h2quic"
|
||||
"github.com/lucas-clemente/quic-go/internal/testdata"
|
||||
|
||||
_ "github.com/lucas-clemente/quic-go/integrationtests/tools/testlog"
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -28,9 +23,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
server *h2quic.Server
|
||||
dataMan dataManager
|
||||
port string
|
||||
clientPath string
|
||||
serverPath string
|
||||
)
|
||||
@@ -40,23 +33,17 @@ func TestIntegration(t *testing.T) {
|
||||
RunSpecs(t, "Integration Tests Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(setupHTTPHandlers)
|
||||
var _ = JustBeforeEach(testserver.StartQuicServer)
|
||||
|
||||
var _ = BeforeEach(func() {
|
||||
var _ = AfterEach(testserver.StopQuicServer)
|
||||
|
||||
func init() {
|
||||
_, thisfile, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
Fail("Failed to get current path")
|
||||
panic("Failed to get current path")
|
||||
}
|
||||
clientPath = filepath.Join(thisfile, fmt.Sprintf("../../../quic-clients/client-%s-debug", runtime.GOOS))
|
||||
serverPath = filepath.Join(thisfile, fmt.Sprintf("../../../quic-clients/server-%s-debug", runtime.GOOS))
|
||||
})
|
||||
|
||||
var _ = JustBeforeEach(startQuicServer)
|
||||
|
||||
var _ = AfterEach(stopQuicServer)
|
||||
|
||||
func setupHTTPHandlers() {
|
||||
defer GinkgoRecover()
|
||||
|
||||
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
|
||||
defer GinkgoRecover()
|
||||
@@ -79,28 +66,4 @@ func setupHTTPHandlers() {
|
||||
_, err = w.Write(body)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func startQuicServer() {
|
||||
server = &h2quic.Server{
|
||||
Server: &http.Server{
|
||||
TLSConfig: testdata.GetTLSConfig(),
|
||||
},
|
||||
}
|
||||
|
||||
addr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
conn, err := net.ListenUDP("udp", addr)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
port = strconv.Itoa(conn.LocalAddr().(*net.UDPAddr).Port)
|
||||
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
server.Serve(conn)
|
||||
}()
|
||||
}
|
||||
|
||||
func stopQuicServer() {
|
||||
Expect(server.Close()).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -60,7 +61,7 @@ var _ = Describe("Random RTT", func() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var err error
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:", quicproxy.Opts{
|
||||
RemoteAddr: "localhost:" + port,
|
||||
RemoteAddr: "localhost:" + testserver.Port(),
|
||||
DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration {
|
||||
return getRandomDuration(minRtt, maxRtt)
|
||||
},
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -26,7 +27,7 @@ var _ = Describe("non-zero RTT", func() {
|
||||
runRTTTest := func(rtt time.Duration, version protocol.VersionNumber) {
|
||||
var err error
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:", quicproxy.Opts{
|
||||
RemoteAddr: "localhost:" + port,
|
||||
RemoteAddr: "localhost:" + testserver.Port(),
|
||||
DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration {
|
||||
return rtt / 2
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user