diff --git a/integrationtests/gquic/data_manager_test.go b/integrationtests/gquic/data_manager_test.go deleted file mode 100644 index ba310344..00000000 --- a/integrationtests/gquic/data_manager_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package gquic_test - -import ( - "crypto/md5" - "math/rand" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - -) - -type dataManager struct { - data []byte - md5 []byte -} - -func (m *dataManager) GenerateData(len int) error { - m.data = make([]byte, len) - r := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) - _, err := r.Read(m.data) - if err != nil { - return err - } - sum := md5.Sum(m.data) - m.md5 = sum[:] - return nil -} - -func (m *dataManager) GetData() []byte { - return m.data -} - -func (m *dataManager) GetMD5() []byte { - return m.md5 -} - -var _ = Describe("Data Manager", func() { - dm := dataManager{} - - It("generates data", func() { - dm.GenerateData(1337) - data := dm.GetData() - Expect(data).To(HaveLen(1337)) - Expect(dm.GetMD5()).To(HaveLen(16)) - }) - - It("generates random data", func() { - dm.GenerateData(1337) - data1 := dm.GetData() - md51 := dm.GetMD5() - dm.GenerateData(1337) - data2 := dm.GetData() - md52 := dm.GetMD5() - Expect(data1).ToNot(Equal(data2)) - Expect(md51).ToNot(Equal(md52)) - }) -}) diff --git a/integrationtests/gquic/drop_test.go b/integrationtests/gquic/drop_test.go index 41705ffa..a3f710b0 100644 --- a/integrationtests/gquic/drop_test.go +++ b/integrationtests/gquic/drop_test.go @@ -16,11 +16,7 @@ import ( . "github.com/onsi/gomega/gexec" ) -var _ = Describe("Drop Proxy", func() { - BeforeEach(func() { - dataMan.GenerateData(dataLen) - }) - +var _ = Describe("Drop tests", func() { var proxy *quicproxy.QuicProxy runDropTest := func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber) { @@ -36,14 +32,14 @@ var _ = Describe("Drop Proxy", func() { "--quic-version="+strconv.Itoa(int(version)), "--host=127.0.0.1", "--port="+strconv.Itoa(proxy.LocalPort()), - "https://quic.clemente.io/data", + "https://quic.clemente.io/prdata", ) session, err := Start(command, nil, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) defer session.Kill() Eventually(session, 20).Should(Exit(0)) - Expect(bytes.Contains(session.Out.Contents(), dataMan.GetData())).To(BeTrue()) + Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue()) } AfterEach(func() { diff --git a/integrationtests/gquic/gquic_suite_test.go b/integrationtests/gquic/gquic_suite_test.go index e1fbc3f2..e79243bb 100644 --- a/integrationtests/gquic/gquic_suite_test.go +++ b/integrationtests/gquic/gquic_suite_test.go @@ -2,9 +2,6 @@ package gquic_test import ( "fmt" - "io" - "io/ioutil" - "net/http" "path/filepath" "runtime" @@ -17,13 +14,7 @@ import ( "testing" ) -const ( - dataLen = 500 * 1024 // 500 KB - dataLongLen = 50 * 1024 * 1024 // 50 MB -) - var ( - dataMan dataManager clientPath string serverPath string ) @@ -44,26 +35,4 @@ func init() { } 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)) - - http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { - defer GinkgoRecover() - _, err := io.WriteString(w, "Hello, World!\n") - Expect(err).NotTo(HaveOccurred()) - }) - - http.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) { - defer GinkgoRecover() - data := dataMan.GetData() - Expect(data).ToNot(HaveLen(0)) - _, err := w.Write(data) - Expect(err).NotTo(HaveOccurred()) - }) - - http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) { - defer GinkgoRecover() - body, err := ioutil.ReadAll(r.Body) - Expect(err).NotTo(HaveOccurred()) - _, err = w.Write(body) - Expect(err).NotTo(HaveOccurred()) - }) } diff --git a/integrationtests/gquic/integration_test.go b/integrationtests/gquic/integration_test.go index d24615c1..2d12af4b 100644 --- a/integrationtests/gquic/integration_test.go +++ b/integrationtests/gquic/integration_test.go @@ -19,10 +19,6 @@ import ( ) var _ = Describe("Integration tests", func() { - BeforeEach(func() { - dataMan.GenerateData(dataLen) - }) - for i := range protocol.SupportedVersions { version := protocol.SupportedVersions[i] @@ -66,13 +62,13 @@ var _ = Describe("Integration tests", func() { "--quic-version="+strconv.Itoa(int(version)), "--host=127.0.0.1", "--port="+testserver.Port(), - "https://quic.clemente.io/data", + "https://quic.clemente.io/prdata", ) session, err := Start(command, nil, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) defer session.Kill() Eventually(session, 10).Should(Exit(0)) - Expect(bytes.Contains(session.Out.Contents(), dataMan.GetData())).To(BeTrue()) + Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue()) }) It("gets many copies of a file in parallel", func() { @@ -87,13 +83,13 @@ var _ = Describe("Integration tests", func() { "--quic-version="+strconv.Itoa(int(version)), "--host=127.0.0.1", "--port="+testserver.Port(), - "https://quic.clemente.io/data", + "https://quic.clemente.io/prdata", ) session, err := Start(command, nil, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) defer session.Kill() Eventually(session, 20).Should(Exit(0)) - Expect(bytes.Contains(session.Out.Contents(), dataMan.GetData())).To(BeTrue()) + Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue()) }() } wg.Wait() diff --git a/integrationtests/gquic/random_rtt_test.go b/integrationtests/gquic/random_rtt_test.go index 336d780e..e458272e 100644 --- a/integrationtests/gquic/random_rtt_test.go +++ b/integrationtests/gquic/random_rtt_test.go @@ -51,10 +51,6 @@ var _ = Describe("Random Duration Generator", func() { }) var _ = Describe("Random RTT", func() { - BeforeEach(func() { - dataMan.GenerateData(dataLen) - }) - var proxy *quicproxy.QuicProxy runRTTTest := func(minRtt, maxRtt time.Duration, version protocol.VersionNumber) { @@ -73,14 +69,14 @@ var _ = Describe("Random RTT", func() { "--quic-version="+strconv.Itoa(int(version)), "--host=127.0.0.1", "--port="+strconv.Itoa(proxy.LocalPort()), - "https://quic.clemente.io/data", + "https://quic.clemente.io/prdata", ) session, err := Start(command, nil, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) defer session.Kill() Eventually(session, 20).Should(Exit(0)) - Expect(bytes.Contains(session.Out.Contents(), dataMan.GetData())).To(BeTrue()) + Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue()) } AfterEach(func() { diff --git a/integrationtests/gquic/rtt_test.go b/integrationtests/gquic/rtt_test.go index 76489b5a..333d07bb 100644 --- a/integrationtests/gquic/rtt_test.go +++ b/integrationtests/gquic/rtt_test.go @@ -18,10 +18,6 @@ import ( ) var _ = Describe("non-zero RTT", func() { - BeforeEach(func() { - dataMan.GenerateData(dataLen) - }) - var proxy *quicproxy.QuicProxy runRTTTest := func(rtt time.Duration, version protocol.VersionNumber) { @@ -39,14 +35,14 @@ var _ = Describe("non-zero RTT", func() { "--quic-version="+strconv.Itoa(int(version)), "--host=127.0.0.1", "--port="+strconv.Itoa(proxy.LocalPort()), - "https://quic.clemente.io/data", + "https://quic.clemente.io/prdata", ) session, err := Start(command, nil, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) defer session.Kill() Eventually(session, 20).Should(Exit(0)) - Expect(bytes.Contains(session.Out.Contents(), dataMan.GetData())).To(BeTrue()) + Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue()) } AfterEach(func() { @@ -62,7 +58,6 @@ var _ = Describe("non-zero RTT", func() { roundTrips := [...]int{10, 50, 100, 200} for _, rtt := range roundTrips { It(fmt.Sprintf("gets a 500kB file with %dms RTT", rtt), func() { - dataMan.GenerateData(dataLen) runRTTTest(time.Duration(rtt)*time.Millisecond, version) }) } diff --git a/integrationtests/gquic/server_test.go b/integrationtests/gquic/server_test.go index c064b939..b553afd8 100644 --- a/integrationtests/gquic/server_test.go +++ b/integrationtests/gquic/server_test.go @@ -18,6 +18,8 @@ import ( "strconv" "time" + "github.com/lucas-clemente/quic-go/integrationtests/tools/testserver" + "github.com/lucas-clemente/quic-go/h2quic" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -178,9 +180,7 @@ var _ = Describe("Server tests", func() { }) It("downloads a small file", func() { - dataMan.GenerateData(dataLen) - data := dataMan.GetData() - createDownloadFile("file.dat", data) + createDownloadFile("file.dat", testserver.PRData) startServer() defer stopServer() @@ -190,13 +190,11 @@ var _ = Describe("Server tests", func() { Expect(rsp.StatusCode).To(Equal(200)) body, err := ioutil.ReadAll(gbytes.TimeoutReader(rsp.Body, 5*time.Second)) Expect(err).ToNot(HaveOccurred()) - Expect(body).To(Equal(data)) + Expect(body).To(Equal(testserver.PRData)) }) It("downloads a large file", func() { - dataMan.GenerateData(dataLongLen) - data := dataMan.GetData() - createDownloadFile("file.dat", data) + createDownloadFile("file.dat", testserver.PRDataLong) startServer() defer stopServer() @@ -206,6 +204,6 @@ var _ = Describe("Server tests", func() { Expect(rsp.StatusCode).To(Equal(200)) body, err := ioutil.ReadAll(gbytes.TimeoutReader(rsp.Body, 20*time.Second)) Expect(err).ToNot(HaveOccurred()) - Expect(body).To(Equal(data)) + Expect(body).To(Equal(testserver.PRDataLong)) }) }) diff --git a/integrationtests/gquic/client_test.go b/integrationtests/self/client_test.go similarity index 84% rename from integrationtests/gquic/client_test.go rename to integrationtests/self/client_test.go index 5fbfae6f..11bd6584 100644 --- a/integrationtests/gquic/client_test.go +++ b/integrationtests/self/client_test.go @@ -1,4 +1,4 @@ -package gquic_test +package self_test import ( "bytes" @@ -32,9 +32,11 @@ var _ = Describe("Client tests", func() { client = &http.Client{ Transport: &h2quic.RoundTripper{}, } + testserver.StartQuicServer() }) AfterEach(func() { + testserver.StopQuicServer() protocol.SupportedVersions = supportedVersions }) @@ -56,34 +58,34 @@ var _ = Describe("Client tests", func() { }) It("downloads a small file", func() { - dataMan.GenerateData(dataLen) - resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/data") + resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/prdata") Expect(err).ToNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(200)) body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second)) Expect(err).ToNot(HaveOccurred()) - Expect(body).To(Equal(dataMan.GetData())) + Expect(body).To(Equal(testserver.PRData)) }) It("downloads a large file", func() { - dataMan.GenerateData(dataLongLen) - resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/data") + resp, err := client.Get("https://quic.clemente.io:" + testserver.Port() + "/prdatalong") Expect(err).ToNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(200)) body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 20*time.Second)) Expect(err).ToNot(HaveOccurred()) - Expect(body).To(Equal(dataMan.GetData())) + Expect(body).To(Equal(testserver.PRDataLong)) }) It("uploads a file", func() { - dataMan.GenerateData(dataLen) - data := bytes.NewReader(dataMan.GetData()) - resp, err := client.Post("https://quic.clemente.io:"+testserver.Port()+"/echo", "text/plain", data) + resp, err := client.Post( + "https://quic.clemente.io:"+testserver.Port()+"/echo", + "text/plain", + bytes.NewReader(testserver.PRData), + ) Expect(err).ToNot(HaveOccurred()) Expect(resp.StatusCode).To(Equal(200)) body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second)) Expect(err).ToNot(HaveOccurred()) - Expect(body).To(Equal(dataMan.GetData())) + Expect(bytes.Equal(body, testserver.PRData)).To(BeTrue()) }) }) } diff --git a/integrationtests/tools/testserver/server.go b/integrationtests/tools/testserver/server.go index ee6dfaea..05ca66dd 100644 --- a/integrationtests/tools/testserver/server.go +++ b/integrationtests/tools/testserver/server.go @@ -1,6 +1,8 @@ package testserver import ( + "io" + "io/ioutil" "net" "net/http" "strconv" @@ -46,6 +48,20 @@ func init() { _, err := w.Write(PRDataLong) Expect(err).NotTo(HaveOccurred()) }) + + http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { + defer GinkgoRecover() + _, err := io.WriteString(w, "Hello, World!\n") + Expect(err).NotTo(HaveOccurred()) + }) + + http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) { + defer GinkgoRecover() + body, err := ioutil.ReadAll(r.Body) + Expect(err).NotTo(HaveOccurred()) + _, err = w.Write(body) + Expect(err).NotTo(HaveOccurred()) + }) } // See https://en.wikipedia.org/wiki/Lehmer_random_number_generator