forked from quic-go/quic-go
move UDP Proxy to subpackage in integration tests
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/proxy"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -17,40 +18,40 @@ import (
|
||||
. "github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
var proxy *UDPProxy
|
||||
|
||||
func runDropTest(incomingPacketDropper, outgoingPacketDropper dropCallback, version protocol.VersionNumber) {
|
||||
proxyPort := 12345
|
||||
|
||||
clientPath := fmt.Sprintf(
|
||||
"%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug",
|
||||
os.Getenv("GOPATH"),
|
||||
runtime.GOOS,
|
||||
)
|
||||
|
||||
iPort, _ := strconv.Atoi(port)
|
||||
var err error
|
||||
proxy, err = NewUDPProxy(proxyPort, "localhost", iPort, incomingPacketDropper, outgoingPacketDropper, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
command := exec.Command(
|
||||
clientPath,
|
||||
"--quic-version="+strconv.Itoa(int(version)),
|
||||
"--host=127.0.0.1",
|
||||
"--port="+strconv.Itoa(proxyPort),
|
||||
"https://quic.clemente.io/data",
|
||||
)
|
||||
|
||||
session, err := Start(command, nil, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
defer session.Kill()
|
||||
Eventually(session, 4).Should(Exit(0))
|
||||
Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue())
|
||||
}
|
||||
|
||||
var _ = Describe("Drop Proxy", func() {
|
||||
var dropproxy *proxy.UDPProxy
|
||||
|
||||
runDropTest := func(incomingPacketDropper, outgoingPacketDropper proxy.DropCallback, version protocol.VersionNumber) {
|
||||
proxyPort := 12345
|
||||
|
||||
clientPath := fmt.Sprintf(
|
||||
"%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug",
|
||||
os.Getenv("GOPATH"),
|
||||
runtime.GOOS,
|
||||
)
|
||||
|
||||
iPort, _ := strconv.Atoi(port)
|
||||
var err error
|
||||
dropproxy, err = proxy.NewUDPProxy(proxyPort, "localhost", iPort, incomingPacketDropper, outgoingPacketDropper, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
command := exec.Command(
|
||||
clientPath,
|
||||
"--quic-version="+strconv.Itoa(int(version)),
|
||||
"--host=127.0.0.1",
|
||||
"--port="+strconv.Itoa(proxyPort),
|
||||
"https://quic.clemente.io/data",
|
||||
)
|
||||
|
||||
session, err := Start(command, nil, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
defer session.Kill()
|
||||
Eventually(session, 4).Should(Exit(0))
|
||||
Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue())
|
||||
}
|
||||
|
||||
AfterEach(func() {
|
||||
proxy.Stop()
|
||||
dropproxy.Stop()
|
||||
time.Sleep(time.Millisecond)
|
||||
})
|
||||
|
||||
@@ -59,7 +60,7 @@ var _ = Describe("Drop Proxy", func() {
|
||||
|
||||
Context(fmt.Sprintf("with quic version %d", version), func() {
|
||||
Context("dropping every 4th packet after the crypto handshake", func() {
|
||||
dropper := func(p PacketNumber) bool {
|
||||
dropper := func(p proxy.PacketNumber) bool {
|
||||
if p <= 5 { // don't interfere with the crypto handshake
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package integrationtests
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -16,8 +16,12 @@ type connection struct {
|
||||
outgoingPacketCounter PacketNumber
|
||||
}
|
||||
|
||||
// A PacketNumber is a packet number for the UDP Proxy
|
||||
// note that this does not necessarily correspond to the QUIC packet number
|
||||
type PacketNumber uint64
|
||||
type dropCallback func(PacketNumber) bool
|
||||
|
||||
// DropCallback is a callback that determines which packet gets dropped
|
||||
type DropCallback func(PacketNumber) bool
|
||||
|
||||
// UDPProxy is a UDP proxy
|
||||
type UDPProxy struct {
|
||||
@@ -25,8 +29,8 @@ type UDPProxy struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
proxyConn *net.UDPConn
|
||||
dropIncomingPacket dropCallback
|
||||
dropOutgoingPacket dropCallback
|
||||
dropIncomingPacket DropCallback
|
||||
dropOutgoingPacket DropCallback
|
||||
rtt time.Duration
|
||||
|
||||
// Mapping from client addresses (as host:port) to connection
|
||||
@@ -34,7 +38,7 @@ type UDPProxy struct {
|
||||
}
|
||||
|
||||
// NewUDPProxy creates a new UDP proxy
|
||||
func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket dropCallback, rtt time.Duration) (*UDPProxy, error) {
|
||||
func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket DropCallback, rtt time.Duration) (*UDPProxy, error) {
|
||||
dontDrop := func(p PacketNumber) bool {
|
||||
return false
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package integrationtests
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
type packetData []byte
|
||||
|
||||
var _ = Describe("Integrationtests", func() {
|
||||
var _ = Describe("UDP Proxy", func() {
|
||||
var serverPort int
|
||||
|
||||
BeforeEach(func() {
|
||||
13
integrationtests/proxy/udpproxy_suite_test.go
Normal file
13
integrationtests/proxy/udpproxy_suite_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQuicGo(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "UDP Proxy")
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||
"github.com/lucas-clemente/quic-go/integrationtests/proxy"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -18,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
var _ = Describe("RTT", func() {
|
||||
var rttProxy *UDPProxy
|
||||
var rttProxy *proxy.UDPProxy
|
||||
|
||||
runRTTTest := func(rtt time.Duration, version protocol.VersionNumber) {
|
||||
proxyPort := 12345
|
||||
@@ -31,7 +32,7 @@ var _ = Describe("RTT", func() {
|
||||
|
||||
iPort, _ := strconv.Atoi(port)
|
||||
var err error
|
||||
rttProxy, err = NewUDPProxy(proxyPort, "localhost", iPort, nil, nil, rtt)
|
||||
rttProxy, err = proxy.NewUDPProxy(proxyPort, "localhost", iPort, nil, nil, rtt)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
command := exec.Command(
|
||||
|
||||
Reference in New Issue
Block a user