From 64b34b52a8d3b1d50c758d787cf73493b0ab9c98 Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Thu, 2 Jun 2016 13:35:42 +0200 Subject: [PATCH] add integration tests for loading larger files ref #152 --- h2quic/integration_test.go | 57 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/h2quic/integration_test.go b/h2quic/integration_test.go index 2c148fdfb..f139e4cd5 100644 --- a/h2quic/integration_test.go +++ b/h2quic/integration_test.go @@ -1,6 +1,8 @@ package h2quic_test import ( + "bytes" + "crypto/rand" "fmt" "io" "net/http" @@ -8,6 +10,7 @@ import ( "os/exec" "runtime" "strconv" + "sync" "time" "github.com/lucas-clemente/quic-go/h2quic" @@ -26,21 +29,32 @@ const port = "6729" const host = "127.0.0.1" const addr = host + ":" + port +const dataLen = 50 * 1024 + var _ = Describe("Integration tests", func() { var ( server *h2quic.Server clientPath string + data []byte ) http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello, World!\n") }) + http.HandleFunc("/data", func(w http.ResponseWriter, r *http.Request) { + w.Write(data) + }) + http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) { io.Copy(w, r.Body) }) BeforeSuite(func() { + data = make([]byte, dataLen) + _, err := rand.Read(data) + Expect(err).NotTo(HaveOccurred()) + clientPath = fmt.Sprintf( "%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug", os.Getenv("GOPATH"), @@ -64,9 +78,11 @@ var _ = Describe("Integration tests", func() { Expect(err).NotTo(HaveOccurred()) }) - for _, version := range protocol.SupportedVersions { + for i := range protocol.SupportedVersions { + version := protocol.SupportedVersions[i] + Context(fmt.Sprintf("with quic version %d", version), func() { - It("downloads a single file", func() { + It("gets a simple file", func() { command := exec.Command( clientPath, "--quic-version="+strconv.Itoa(int(version)), @@ -94,6 +110,43 @@ var _ = Describe("Integration tests", func() { Eventually(session).Should(Exit(0)) Expect(session.Out).To(Say("Response:\nheaders: HTTP/1.1 200\nstatus: 200\n\nbody: foo\n")) }) + + It("gets a large file", func() { + command := exec.Command( + clientPath, + "--quic-version="+strconv.Itoa(int(version)), + "--host="+host, + "--port="+port, + "https://quic.clemente.io/data", + ) + session, err := Start(command, nil, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + Eventually(session).Should(Exit(0)) + Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue()) + }) + + It("gets many large files in parallel", func() { + wg := sync.WaitGroup{} + for i := 0; i < 10; i++ { + wg.Add(1) + go func() { + defer wg.Done() + defer GinkgoRecover() + command := exec.Command( + clientPath, + "--quic-version="+strconv.Itoa(int(version)), + "--host="+host, + "--port="+port, + "https://quic.clemente.io/data", + ) + session, err := Start(command, nil, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + Eventually(session).Should(Exit(0)) + Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue()) + }() + } + wg.Wait() + }) }) } })