add integration tests for loading larger files

ref #152
This commit is contained in:
Lucas Clemente
2016-06-02 13:35:42 +02:00
parent 21db6f9270
commit 64b34b52a8

View File

@@ -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()
})
})
}
})