remove the testserver package

This commit is contained in:
Marten Seemann 2019-11-25 12:54:58 +07:00
parent dde21d2f72
commit 07dcbc8496
13 changed files with 171 additions and 202 deletions

View file

@ -19,7 +19,6 @@ import (
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/testdata"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/quictrace"
@ -41,6 +40,17 @@ type Size interface {
Size() int64
}
// See https://en.wikipedia.org/wiki/Lehmer_random_number_generator
func generatePRData(l int) []byte {
res := make([]byte, l)
seed := uint64(1)
for i := 0; i < l; i++ {
seed = seed * 48271 % 2147483647
res[i] = byte(seed)
}
return res
}
var tracer quictrace.Tracer
func init() {
@ -93,7 +103,7 @@ func setupHandler(www string, trace bool) http.Handler {
w.WriteHeader(400)
return
}
w.Write(testserver.GeneratePRData(int(num)))
w.Write(generatePRData(int(num)))
})
}

View file

@ -12,7 +12,6 @@ import (
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -43,7 +42,7 @@ var _ = Describe("Stream Cancelations", func() {
defer wg.Done()
str, err := sess.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
if _, err = str.Write(testserver.PRData); err != nil {
if _, err = str.Write(PRData); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
atomic.AddInt32(&canceledCounter, 1)
return
@ -87,7 +86,7 @@ var _ = Describe("Stream Cancelations", func() {
}
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}()
}
wg.Wait()
@ -125,17 +124,17 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).ToNot(HaveOccurred())
// only read some data from about 1/3 of the streams
if rand.Int31()%3 != 0 {
length := int(rand.Int31n(int32(len(testserver.PRData) - 1)))
length := int(rand.Int31n(int32(len(PRData) - 1)))
data, err := ioutil.ReadAll(io.LimitReader(str, int64(length)))
Expect(err).ToNot(HaveOccurred())
str.CancelRead(quic.ErrorCode(str.StreamID()))
Expect(data).To(Equal(testserver.PRData[:length]))
Expect(data).To(Equal(PRData[:length]))
atomic.AddInt32(&canceledCounter, 1)
return
}
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}()
}
wg.Wait()
@ -177,7 +176,7 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}()
}
wg.Wait()
@ -211,7 +210,7 @@ var _ = Describe("Stream Cancelations", func() {
atomic.AddInt32(&canceledCounter, 1)
return
}
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
}()
@ -238,14 +237,14 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).ToNot(HaveOccurred())
// only write some data from about 1/3 of the streams, then cancel
if rand.Int31()%3 != 0 {
length := int(rand.Int31n(int32(len(testserver.PRData) - 1)))
_, err = str.Write(testserver.PRData[:length])
length := int(rand.Int31n(int32(len(PRData) - 1)))
_, err = str.Write(PRData[:length])
Expect(err).ToNot(HaveOccurred())
str.CancelWrite(quic.ErrorCode(str.StreamID()))
atomic.AddInt32(&canceledCounter, 1)
return
}
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
}()
@ -280,7 +279,7 @@ var _ = Describe("Stream Cancelations", func() {
str.CancelWrite(quic.ErrorCode(str.StreamID()))
return
}
if _, err = str.Write(testserver.PRData); err != nil {
if _, err = str.Write(PRData); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
@ -318,7 +317,7 @@ var _ = Describe("Stream Cancelations", func() {
return
}
atomic.AddInt32(&counter, 1)
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}()
}
wg.Wait()
@ -350,15 +349,15 @@ var _ = Describe("Stream Cancelations", func() {
str, err := sess.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
// cancel about half of the streams
length := len(testserver.PRData)
length := len(PRData)
if rand.Int31()%2 == 0 {
length = int(rand.Int31n(int32(len(testserver.PRData) - 1)))
length = int(rand.Int31n(int32(len(PRData) - 1)))
}
if _, err = str.Write(testserver.PRData[:length]); err != nil {
if _, err = str.Write(PRData[:length]); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
if length < len(testserver.PRData) {
if length < len(PRData) {
str.CancelWrite(quic.ErrorCode(str.StreamID()))
} else {
Expect(str.Close()).To(Succeed())
@ -388,10 +387,10 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).ToNot(HaveOccurred())
r := io.Reader(str)
length := len(testserver.PRData)
length := len(PRData)
// cancel around half of the streams
if rand.Int31()%2 == 0 {
length = int(rand.Int31n(int32(len(testserver.PRData) - 1)))
length = int(rand.Int31n(int32(len(PRData) - 1)))
r = io.LimitReader(str, int64(length))
}
data, err := ioutil.ReadAll(r)
@ -399,14 +398,14 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(data).To(Equal(testserver.PRData[:length]))
if length < len(testserver.PRData) {
Expect(data).To(Equal(PRData[:length]))
if length < len(PRData) {
str.CancelRead(quic.ErrorCode(str.StreamID()))
return
}
atomic.AddInt32(&counter, 1)
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}()
}
wg.Wait()
@ -437,7 +436,7 @@ var _ = Describe("Stream Cancelations", func() {
defer GinkgoRecover()
str, err := sess.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
}()
@ -476,7 +475,7 @@ var _ = Describe("Stream Cancelations", func() {
}
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
wg.Done()
}()
}
@ -520,7 +519,7 @@ var _ = Describe("Stream Cancelations", func() {
numOpened++
go func(str quic.SendStream) {
defer GinkgoRecover()
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
}(str)
@ -547,7 +546,7 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
wg.Done()
}()
}

View file

@ -8,8 +8,8 @@ import (
"net"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -35,7 +35,7 @@ var _ = Describe("Connection ID lengths tests", func() {
str, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
}()
}
@ -56,7 +56,7 @@ var _ = Describe("Connection ID lengths tests", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}
It("downloads a file using a 0-byte connection ID for the client", func() {

View file

@ -8,7 +8,6 @@ import (
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -60,7 +59,7 @@ var _ = Describe("Stream deadline tests", func() {
done := make(chan struct{})
go func() {
defer GinkgoRecover()
_, err := serverStr.Write(testserver.PRDataLong)
_, err := serverStr.Write(PRDataLong)
Expect(err).ToNot(HaveOccurred())
close(done)
}()
@ -68,9 +67,9 @@ var _ = Describe("Stream deadline tests", func() {
var bytesRead int
var timeoutCounter int
buf := make([]byte, 1<<10)
data := make([]byte, len(testserver.PRDataLong))
data := make([]byte, len(PRDataLong))
clientStr.SetReadDeadline(time.Now().Add(timeout))
for bytesRead < len(testserver.PRDataLong) {
for bytesRead < len(PRDataLong) {
n, err := clientStr.Read(buf)
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
timeoutCounter++
@ -81,7 +80,7 @@ var _ = Describe("Stream deadline tests", func() {
copy(data[bytesRead:], buf[:n])
bytesRead += n
}
Expect(data).To(Equal(testserver.PRDataLong))
Expect(data).To(Equal(PRDataLong))
// make sure the test actually worked an Read actually ran into the deadline a few times
Expect(timeoutCounter).To(BeNumerically(">=", 10))
Eventually(done).Should(BeClosed())
@ -91,14 +90,14 @@ var _ = Describe("Stream deadline tests", func() {
const timeout = 20 * time.Millisecond
go func() {
defer GinkgoRecover()
_, err := serverStr.Write(testserver.PRDataLong)
_, err := serverStr.Write(PRDataLong)
Expect(err).ToNot(HaveOccurred())
}()
var bytesRead int
var timeoutCounter int
buf := make([]byte, 1<<10)
data := make([]byte, len(testserver.PRDataLong))
data := make([]byte, len(PRDataLong))
clientStr.SetReadDeadline(time.Now().Add(timeout))
deadlineDone := make(chan struct{})
received := make(chan struct{})
@ -115,7 +114,7 @@ var _ = Describe("Stream deadline tests", func() {
}
}()
for bytesRead < len(testserver.PRDataLong) {
for bytesRead < len(PRDataLong) {
n, err := clientStr.Read(buf)
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
timeoutCounter++
@ -126,7 +125,7 @@ var _ = Describe("Stream deadline tests", func() {
bytesRead += n
}
close(received)
Expect(data).To(Equal(testserver.PRDataLong))
Expect(data).To(Equal(PRDataLong))
// make sure the test actually worked an Read actually ran into the deadline a few times
Expect(timeoutCounter).To(BeNumerically(">=", 10))
Eventually(deadlineDone).Should(BeClosed())
@ -141,15 +140,15 @@ var _ = Describe("Stream deadline tests", func() {
defer GinkgoRecover()
data, err := ioutil.ReadAll(serverStr)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRDataLong))
Expect(data).To(Equal(PRDataLong))
close(done)
}()
var bytesWritten int
var timeoutCounter int
clientStr.SetWriteDeadline(time.Now().Add(timeout))
for bytesWritten < len(testserver.PRDataLong) {
n, err := clientStr.Write(testserver.PRDataLong[bytesWritten:])
for bytesWritten < len(PRDataLong) {
n, err := clientStr.Write(PRDataLong[bytesWritten:])
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
timeoutCounter++
clientStr.SetWriteDeadline(time.Now().Add(timeout))
@ -171,7 +170,7 @@ var _ = Describe("Stream deadline tests", func() {
defer GinkgoRecover()
data, err := ioutil.ReadAll(serverStr)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRDataLong))
Expect(data).To(Equal(PRDataLong))
close(readDone)
}()
@ -193,8 +192,8 @@ var _ = Describe("Stream deadline tests", func() {
var bytesWritten int
var timeoutCounter int
clientStr.SetWriteDeadline(time.Now().Add(timeout))
for bytesWritten < len(testserver.PRDataLong) {
n, err := clientStr.Write(testserver.PRDataLong[bytesWritten:])
for bytesWritten < len(PRDataLong) {
n, err := clientStr.Write(PRDataLong[bytesWritten:])
if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
timeoutCounter++
} else {

View file

@ -6,13 +6,15 @@ import (
"context"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"strconv"
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"
@ -27,16 +29,74 @@ type streamCancelError interface {
}
var _ = Describe("HTTP tests", func() {
var client *http.Client
var (
mux *http.ServeMux
client *http.Client
server *http3.Server
stoppedServing chan struct{}
port string
)
versions := protocol.SupportedVersions
BeforeEach(func() {
testserver.StartQuicServer(versions)
mux = http.NewServeMux()
mux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
io.WriteString(w, "Hello, World!\n") // don't check the error here. Stream may be reset.
})
mux.HandleFunc("/prdata", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
sl := r.URL.Query().Get("len")
if sl != "" {
var err error
l, err := strconv.Atoi(sl)
Expect(err).NotTo(HaveOccurred())
w.Write(GeneratePRData(l)) // don't check the error here. Stream may be reset.
} else {
w.Write(PRData) // don't check the error here. Stream may be reset.
}
})
mux.HandleFunc("/prdatalong", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
w.Write(PRDataLong) // don't check the error here. Stream may be reset.
})
mux.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
body, err := ioutil.ReadAll(r.Body)
Expect(err).NotTo(HaveOccurred())
w.Write(body) // don't check the error here. Stream may be reset.
})
server = &http3.Server{
Server: &http.Server{
Handler: mux,
TLSConfig: testdata.GetTLSConfig(),
},
QuicConfig: &quic.Config{Versions: versions},
}
addr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0")
Expect(err).NotTo(HaveOccurred())
conn, err := net.ListenUDP("udp", addr)
Expect(err).NotTo(HaveOccurred())
port = strconv.Itoa(conn.LocalAddr().(*net.UDPAddr).Port)
stoppedServing = make(chan struct{})
go func() {
defer GinkgoRecover()
server.Serve(conn)
close(stoppedServing)
}()
})
AfterEach(func() {
testserver.StopQuicServer()
Expect(server.Close()).NotTo(HaveOccurred())
Eventually(stoppedServing).Should(BeClosed())
})
for _, v := range versions {
@ -59,7 +119,7 @@ var _ = Describe("HTTP tests", func() {
})
It("downloads a hello", func() {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/hello")
resp, err := client.Get("https://localhost:" + port + "/hello")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 3*time.Second))
@ -69,14 +129,14 @@ var _ = Describe("HTTP tests", func() {
It("sets and gets request headers", func() {
handlerCalled := make(chan struct{})
http.HandleFunc("/headers/request", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/headers/request", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
Expect(r.Header.Get("foo")).To(Equal("bar"))
Expect(r.Header.Get("lorem")).To(Equal("ipsum"))
close(handlerCalled)
})
req, err := http.NewRequest(http.MethodGet, "https://localhost:"+testserver.Port()+"/headers/request", nil)
req, err := http.NewRequest(http.MethodGet, "https://localhost:"+port+"/headers/request", nil)
Expect(err).ToNot(HaveOccurred())
req.Header.Set("foo", "bar")
req.Header.Set("lorem", "ipsum")
@ -87,13 +147,13 @@ var _ = Describe("HTTP tests", func() {
})
It("sets and gets response headers", func() {
http.HandleFunc("/headers/response", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/headers/response", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
w.Header().Set("foo", "bar")
w.Header().Set("lorem", "ipsum")
})
resp, err := client.Get("https://localhost:" + testserver.Port() + "/headers/response")
resp, err := client.Get("https://localhost:" + port + "/headers/response")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
Expect(resp.Header.Get("foo")).To(Equal("bar"))
@ -101,28 +161,28 @@ var _ = Describe("HTTP tests", func() {
})
It("downloads a small file", func() {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/prdata")
resp, err := client.Get("https://localhost:" + 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(testserver.PRData))
Expect(body).To(Equal(PRData))
})
It("downloads a large file", func() {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/prdatalong")
resp, err := client.Get("https://localhost:" + 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(testserver.PRDataLong))
Expect(body).To(Equal(PRDataLong))
})
It("downloads many hellos", func() {
const num = 150
for i := 0; i < num; i++ {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/hello")
resp, err := client.Get("https://localhost:" + port + "/hello")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 3*time.Second))
@ -135,7 +195,7 @@ var _ = Describe("HTTP tests", func() {
const num = 150
for i := 0; i < num; i++ {
resp, err := client.Get("https://localhost:" + testserver.Port() + "/prdata")
resp, err := client.Get("https://localhost:" + port + "/prdata")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
Expect(resp.Body.Close()).To(Succeed())
@ -144,7 +204,7 @@ var _ = Describe("HTTP tests", func() {
It("posts a small message", func() {
resp, err := client.Post(
"https://localhost:"+testserver.Port()+"/echo",
"https://localhost:"+port+"/echo",
"text/plain",
bytes.NewReader([]byte("Hello, world!")),
)
@ -157,19 +217,19 @@ var _ = Describe("HTTP tests", func() {
It("uploads a file", func() {
resp, err := client.Post(
"https://localhost:"+testserver.Port()+"/echo",
"https://localhost:"+port+"/echo",
"text/plain",
bytes.NewReader(testserver.PRData),
bytes.NewReader(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(testserver.PRData))
Expect(body).To(Equal(PRData))
})
It("uses gzip compression", func() {
http.HandleFunc("/gzipped/hello", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/gzipped/hello", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
Expect(r.Header.Get("Accept-Encoding")).To(Equal("gzip"))
w.Header().Set("Content-Encoding", "gzip")
@ -181,7 +241,7 @@ var _ = Describe("HTTP tests", func() {
})
client.Transport.(*http3.RoundTripper).DisableCompression = false
resp, err := client.Get("https://localhost:" + testserver.Port() + "/gzipped/hello")
resp, err := client.Get("https://localhost:" + port + "/gzipped/hello")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
Expect(resp.Uncompressed).To(BeTrue())
@ -193,7 +253,7 @@ var _ = Describe("HTTP tests", func() {
It("cancels requests", func() {
handlerCalled := make(chan struct{})
http.HandleFunc("/cancel", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/cancel", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
defer close(handlerCalled)
for {
@ -208,7 +268,7 @@ var _ = Describe("HTTP tests", func() {
}
})
req, err := http.NewRequest(http.MethodGet, "https://localhost:"+testserver.Port()+"/cancel", nil)
req, err := http.NewRequest(http.MethodGet, "https://localhost:"+port+"/cancel", nil)
Expect(err).ToNot(HaveOccurred())
ctx, cancel := context.WithCancel(context.Background())
req = req.WithContext(ctx)

View file

@ -8,7 +8,6 @@ import (
"os"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -29,7 +28,7 @@ var _ = Describe("Key Update tests", func() {
str, err := sess.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(testserver.PRDataLong)
_, err = str.Write(PRDataLong)
Expect(err).ToNot(HaveOccurred())
}()
}
@ -52,6 +51,6 @@ var _ = Describe("Key Update tests", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRDataLong))
Expect(data).To(Equal(PRDataLong))
})
})

View file

@ -13,7 +13,6 @@ import (
quic "github.com/lucas-clemente/quic-go"
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/qerr"
"github.com/lucas-clemente/quic-go/internal/testutils"
@ -50,7 +49,7 @@ var _ = Describe("MITM test", func() {
Expect(err).ToNot(HaveOccurred())
str, err := serverSess.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
}()
@ -139,7 +138,7 @@ var _ = Describe("MITM test", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
Expect(sess.Close()).To(Succeed())
}
@ -185,7 +184,7 @@ var _ = Describe("MITM test", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
Expect(sess.Close()).To(Succeed())
}

View file

@ -10,7 +10,6 @@ import (
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testlog"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
@ -35,7 +34,7 @@ var _ = Describe("Multiplexing", func() {
str, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
}()
}
@ -56,7 +55,7 @@ var _ = Describe("Multiplexing", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
}
Context("multiplexing clients on the same conn", func() {

View file

@ -9,7 +9,6 @@ import (
quic "github.com/lucas-clemente/quic-go"
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
@ -47,7 +46,7 @@ var _ = Describe("non-zero RTT", func() {
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(testserver.PRData)
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
str.Close()
close(done)
@ -72,7 +71,7 @@ var _ = Describe("non-zero RTT", func() {
Expect(err).ToNot(HaveOccurred())
data, err := ioutil.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testserver.PRData))
Expect(data).To(Equal(PRData))
sess.Close()
Eventually(done).Should(BeClosed())
})

View file

@ -27,6 +27,29 @@ func getTLSClientConfig() *tls.Config {
}
}
const (
dataLen = 500 * 1024 // 500 KB
dataLenLong = 50 * 1024 * 1024 // 50 MB
)
var (
// PRData contains dataLen bytes of pseudo-random data.
PRData = GeneratePRData(dataLen)
// PRDataLong contains dataLenLong bytes of pseudo-random data.
PRDataLong = GeneratePRData(dataLenLong)
)
// See https://en.wikipedia.org/wiki/Lehmer_random_number_generator
func GeneratePRData(l int) []byte {
res := make([]byte, l)
seed := uint64(1)
for i := 0; i < l; i++ {
seed = seed * 48271 % 2147483647
res[i] = byte(seed)
}
return res
}
func TestSelf(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Self integration tests")

View file

@ -8,7 +8,6 @@ import (
"sync"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
@ -49,7 +48,7 @@ var _ = Describe("Bidirectional streams", func() {
for i := 0; i < numStreams; i++ {
str, err := sess.OpenStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
data := testserver.GeneratePRData(25 * i)
data := GeneratePRData(25 * i)
go func() {
defer GinkgoRecover()
_, err := str.Write(data)

View file

@ -8,7 +8,6 @@ import (
"sync"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/integrationtests/tools/testserver"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
@ -37,7 +36,7 @@ var _ = Describe("Unidirectional Streams", func() {
})
dataForStream := func(id protocol.StreamID) []byte {
return testserver.GeneratePRData(10 * int(id))
return GeneratePRData(10 * int(id))
}
runSendingPeer := func(sess quic.Session) {

View file

@ -1,116 +0,0 @@
package testserver
import (
"io"
"io/ioutil"
"net"
"net/http"
"strconv"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"
//nolint:stylecheck
. "github.com/onsi/ginkgo"
//nolint:stylecheck
. "github.com/onsi/gomega"
)
const (
dataLen = 500 * 1024 // 500 KB
dataLenLong = 50 * 1024 * 1024 // 50 MB
)
var (
// PRData contains dataLen bytes of pseudo-random data.
PRData = GeneratePRData(dataLen)
// PRDataLong contains dataLenLong bytes of pseudo-random data.
PRDataLong = GeneratePRData(dataLenLong)
server *http3.Server
stoppedServing chan struct{}
port string
)
func init() {
http.HandleFunc("/prdata", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
sl := r.URL.Query().Get("len")
if sl != "" {
var err error
l, err := strconv.Atoi(sl)
Expect(err).NotTo(HaveOccurred())
w.Write(GeneratePRData(l)) // don't check the error here. Stream may be reset.
} else {
w.Write(PRData) // don't check the error here. Stream may be reset.
}
})
http.HandleFunc("/prdatalong", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
w.Write(PRDataLong) // don't check the error here. Stream may be reset.
})
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
io.WriteString(w, "Hello, World!\n") // don't check the error here. Stream may be reset.
})
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
body, err := ioutil.ReadAll(r.Body)
Expect(err).NotTo(HaveOccurred())
w.Write(body) // don't check the error here. Stream may be reset.
})
}
// See https://en.wikipedia.org/wiki/Lehmer_random_number_generator
func GeneratePRData(l int) []byte {
res := make([]byte, l)
seed := uint64(1)
for i := 0; i < l; i++ {
seed = seed * 48271 % 2147483647
res[i] = byte(seed)
}
return res
}
// StartQuicServer starts a http3.Server.
// versions is a slice of supported QUIC versions. It may be nil, then all supported versions are used.
func StartQuicServer(versions []protocol.VersionNumber) {
server = &http3.Server{
Server: &http.Server{
TLSConfig: testdata.GetTLSConfig(),
},
QuicConfig: &quic.Config{
Versions: versions,
},
}
addr, err := net.ResolveUDPAddr("udp", "0.0.0.0:0")
Expect(err).NotTo(HaveOccurred())
conn, err := net.ListenUDP("udp", addr)
Expect(err).NotTo(HaveOccurred())
port = strconv.Itoa(conn.LocalAddr().(*net.UDPAddr).Port)
stoppedServing = make(chan struct{})
go func() {
defer GinkgoRecover()
server.Serve(conn)
close(stoppedServing)
}()
}
// StopQuicServer stops the http3.Server.
func StopQuicServer() {
Expect(server.Close()).NotTo(HaveOccurred())
Eventually(stoppedServing).Should(BeClosed())
}
// Port returns the UDP port of the QUIC server.
func Port() string {
return port
}