Add caching to PR data generation and add a separate prdatalong handler

This commit is contained in:
Lucas Clemente 2017-08-18 11:39:55 +02:00
parent 84db78db83
commit 6150e2d05d

View file

@ -12,7 +12,15 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
const (
dataLen = 500 * 1024 // 500 KB
dataLenLong = 50 * 1024 * 1024 // 50 MB
)
var ( var (
PRData = GeneratePRData(dataLen)
PRDataLong = GeneratePRData(dataLenLong)
server *h2quic.Server server *h2quic.Server
port string port string
) )
@ -21,10 +29,21 @@ func init() {
http.HandleFunc("/prdata", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/prdata", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover() defer GinkgoRecover()
sl := r.URL.Query().Get("len") sl := r.URL.Query().Get("len")
l, err := strconv.Atoi(sl) if sl != "" {
Expect(err).NotTo(HaveOccurred()) var err error
data := GeneratePRData(l) l, err := strconv.Atoi(sl)
_, err = w.Write(data) Expect(err).NotTo(HaveOccurred())
_, err = w.Write(GeneratePRData(l))
Expect(err).NotTo(HaveOccurred())
} else {
_, err := w.Write(PRData)
Expect(err).NotTo(HaveOccurred())
}
})
http.HandleFunc("/prdatalong", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
_, err := w.Write(PRDataLong)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
} }