mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
use a kernel determined server address in proxy tests
Now we can execute the proxy tests in parallel without running into "address already in use" errors.
This commit is contained in:
parent
71f7ab1326
commit
7ba9fb0f8b
6 changed files with 24 additions and 27 deletions
|
@ -21,7 +21,7 @@ var _ = Describe("Drop tests", func() {
|
|||
|
||||
runDropTest := func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber) {
|
||||
var err error
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:0", version, quicproxy.Opts{
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:0", version, &quicproxy.Opts{
|
||||
RemoteAddr: "localhost:" + testserver.Port(),
|
||||
DropPacket: dropCallback,
|
||||
})
|
||||
|
|
|
@ -56,7 +56,7 @@ var _ = Describe("Random RTT", func() {
|
|||
runRTTTest := func(minRtt, maxRtt time.Duration, version protocol.VersionNumber) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
var err error
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:", version, quicproxy.Opts{
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:", version, &quicproxy.Opts{
|
||||
RemoteAddr: "localhost:" + testserver.Port(),
|
||||
DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration {
|
||||
return getRandomDuration(minRtt, maxRtt)
|
||||
|
|
|
@ -22,7 +22,7 @@ var _ = Describe("non-zero RTT", func() {
|
|||
|
||||
runRTTTest := func(rtt time.Duration, version protocol.VersionNumber) {
|
||||
var err error
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:", version, quicproxy.Opts{
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:", version, &quicproxy.Opts{
|
||||
RemoteAddr: "localhost:" + testserver.Port(),
|
||||
DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration {
|
||||
return rtt / 2
|
||||
|
|
|
@ -45,7 +45,7 @@ var _ = Describe("Handshake RTT tests", func() {
|
|||
server, err = quic.ListenAddr("localhost:0", testdata.GetTLSConfig(), serverConfig)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// start the proxy
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:0", protocol.VersionWhatever, quicproxy.Opts{
|
||||
proxy, err = quicproxy.NewQuicProxy("localhost:0", protocol.VersionWhatever, &quicproxy.Opts{
|
||||
RemoteAddr: server.Addr().String(),
|
||||
DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration { return rtt / 2 },
|
||||
})
|
||||
|
|
|
@ -75,7 +75,10 @@ type QuicProxy struct {
|
|||
}
|
||||
|
||||
// NewQuicProxy creates a new UDP proxy
|
||||
func NewQuicProxy(local string, version protocol.VersionNumber, opts Opts) (*QuicProxy, error) {
|
||||
func NewQuicProxy(local string, version protocol.VersionNumber, opts *Opts) (*QuicProxy, error) {
|
||||
if opts == nil {
|
||||
opts = &Opts{}
|
||||
}
|
||||
laddr, err := net.ResolveUDPAddr("udp", local)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -18,8 +18,6 @@ import (
|
|||
type packetData []byte
|
||||
|
||||
var _ = Describe("QUIC Proxy", func() {
|
||||
var serverAddr string
|
||||
|
||||
makePacket := func(p protocol.PacketNumber, payload []byte) []byte {
|
||||
b := &bytes.Buffer{}
|
||||
hdr := wire.PublicHeader{
|
||||
|
@ -34,13 +32,9 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
return raw
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
serverAddr = "localhost:7331"
|
||||
})
|
||||
|
||||
Context("Proxy setup and teardown", func() {
|
||||
It("sets up the UDPProxy", func() {
|
||||
proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, Opts{RemoteAddr: serverAddr})
|
||||
proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(proxy.clientDict).To(HaveLen(0))
|
||||
|
||||
|
@ -53,7 +47,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
})
|
||||
|
||||
It("stops the UDPProxy", func() {
|
||||
proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, Opts{RemoteAddr: serverAddr})
|
||||
proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
port := proxy.LocalPort()
|
||||
err = proxy.Close()
|
||||
|
@ -71,7 +65,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
})
|
||||
|
||||
It("has the correct LocalAddr and LocalPort", func() {
|
||||
proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, Opts{RemoteAddr: serverAddr})
|
||||
proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Expect(proxy.LocalAddr().String()).To(Equal("127.0.0.1:" + strconv.Itoa(proxy.LocalPort())))
|
||||
|
@ -90,7 +84,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
proxy *QuicProxy
|
||||
)
|
||||
|
||||
startProxy := func(opts Opts) {
|
||||
startProxy := func(opts *Opts) {
|
||||
var err error
|
||||
proxy, err = NewQuicProxy("localhost:0", protocol.VersionWhatever, opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -113,9 +107,9 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
serverReceivedPackets = make(chan packetData, 100)
|
||||
atomic.StoreInt32(&serverNumPacketsSent, 0)
|
||||
|
||||
// setup a dump UDP server on port 7331
|
||||
// setup a dump UDP server
|
||||
// in production this would be a QUIC server
|
||||
raddr, err := net.ResolveUDPAddr("udp", serverAddr)
|
||||
raddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
serverConn, err = net.ListenUDP("udp", raddr)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -149,7 +143,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
Context("no packet drop", func() {
|
||||
It("relays packets from the client to the server", func() {
|
||||
startProxy(Opts{RemoteAddr: serverAddr})
|
||||
startProxy(&Opts{RemoteAddr: serverConn.LocalAddr().String()})
|
||||
// send the first packet
|
||||
_, err := clientConn.Write(makePacket(1, []byte("foobar")))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -171,7 +165,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
})
|
||||
|
||||
It("relays packets from the server to the client", func() {
|
||||
startProxy(Opts{RemoteAddr: serverAddr})
|
||||
startProxy(&Opts{RemoteAddr: serverConn.LocalAddr().String()})
|
||||
// send the first packet
|
||||
_, err := clientConn.Write(makePacket(1, []byte("foobar")))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -218,8 +212,8 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
Context("Drop Callbacks", func() {
|
||||
It("drops incoming packets", func() {
|
||||
opts := Opts{
|
||||
RemoteAddr: serverAddr,
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
DropPacket: func(d Direction, p protocol.PacketNumber) bool {
|
||||
return d == DirectionIncoming && p%2 == 0
|
||||
},
|
||||
|
@ -236,8 +230,8 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
It("drops outgoing packets", func() {
|
||||
const numPackets = 6
|
||||
opts := Opts{
|
||||
RemoteAddr: serverAddr,
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
DropPacket: func(d Direction, p protocol.PacketNumber) bool {
|
||||
return d == DirectionOutgoing && p%2 == 0
|
||||
},
|
||||
|
@ -280,8 +274,8 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
It("delays incoming packets", func() {
|
||||
delay := 300 * time.Millisecond
|
||||
opts := Opts{
|
||||
RemoteAddr: serverAddr,
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
// delay packet 1 by 200 ms
|
||||
// delay packet 2 by 400 ms
|
||||
// ...
|
||||
|
@ -311,8 +305,8 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
It("delays outgoing packets", func() {
|
||||
const numPackets = 3
|
||||
delay := 300 * time.Millisecond
|
||||
opts := Opts{
|
||||
RemoteAddr: serverAddr,
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
// delay packet 1 by 200 ms
|
||||
// delay packet 2 by 400 ms
|
||||
// ...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue