From 0d8cd978a78f51b37c8a351708c3e42d05875a02 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 1 Aug 2016 16:06:15 +0700 Subject: [PATCH] add an integration test with random RTTs fixes #233 --- integrationtests/random_rtt_test.go | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 integrationtests/random_rtt_test.go diff --git a/integrationtests/random_rtt_test.go b/integrationtests/random_rtt_test.go new file mode 100644 index 000000000..647cf4fe9 --- /dev/null +++ b/integrationtests/random_rtt_test.go @@ -0,0 +1,67 @@ +package integrationtests + +import ( + "bytes" + "fmt" + "os" + "os/exec" + "runtime" + "strconv" + "time" + + _ "github.com/lucas-clemente/quic-clients" // download clients + "github.com/lucas-clemente/quic-go/integrationtests/proxy" + "github.com/lucas-clemente/quic-go/protocol" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" +) + +var _ = Describe("Random RTT", func() { + var rttProxy *proxy.UDPProxy + + runRTTTest := func(minRtt, maxRtt time.Duration, version protocol.VersionNumber) { + proxyPort := 12345 + + clientPath := fmt.Sprintf( + "%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug", + os.Getenv("GOPATH"), + runtime.GOOS, + ) + + iPort, _ := strconv.Atoi(port) + var err error + rttProxy, err = proxy.NewUDPProxy(proxyPort, "localhost", iPort, nil, nil, minRtt, maxRtt) + Expect(err).ToNot(HaveOccurred()) + + command := exec.Command( + clientPath, + "--quic-version="+strconv.Itoa(int(version)), + "--host=127.0.0.1", + "--port="+strconv.Itoa(proxyPort), + "https://quic.clemente.io/data", + ) + + session, err := Start(command, nil, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + defer session.Kill() + Eventually(session, 4).Should(Exit(0)) + Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue()) + } + + AfterEach(func() { + rttProxy.Stop() + time.Sleep(time.Millisecond) + }) + + for i := range protocol.SupportedVersions { + version := protocol.SupportedVersions[i] + + Context(fmt.Sprintf("with quic version %d", version), func() { + It("gets a file a random RTT between 10ms and 30ms", func() { + runRTTTest(10*time.Millisecond, 30*time.Millisecond, version) + }) + }) + } +})