From 3c2b59d20d3e01b195e10c4b881b6818535a116e Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 8 Jun 2016 11:15:51 +0700 Subject: [PATCH] implement basic integration tests with dropped packages ref #167 --- integrationtests/drop.go | 1 + integrationtests/drop_test.go | 94 +++++++++++++++++++ .../integrationtests_suite_test.go | 1 + integrationtests/udp_proxy.go | 10 +- integrationtests/udp_proxy_test.go | 12 +-- 5 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 integrationtests/drop.go create mode 100644 integrationtests/drop_test.go diff --git a/integrationtests/drop.go b/integrationtests/drop.go new file mode 100644 index 00000000..c94303b8 --- /dev/null +++ b/integrationtests/drop.go @@ -0,0 +1 @@ +package integrationtests diff --git a/integrationtests/drop_test.go b/integrationtests/drop_test.go new file mode 100644 index 00000000..6f8fe0c5 --- /dev/null +++ b/integrationtests/drop_test.go @@ -0,0 +1,94 @@ +package integrationtests + +import ( + "bytes" + "fmt" + "os" + "os/exec" + "runtime" + "strconv" + "time" + + _ "github.com/lucas-clemente/quic-clients" // download clients + "github.com/lucas-clemente/quic-go/protocol" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" +) + +var _ = Describe("Drop Proxy", func() { + var proxy *UDPProxy + clientPath := fmt.Sprintf( + "%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug", + os.Getenv("GOPATH"), + runtime.GOOS, + ) + proxyPort := 10001 + + AfterEach(func() { + proxy.Stop() + time.Sleep(time.Millisecond) + }) + + for i := range protocol.SupportedVersions { + version := protocol.SupportedVersions[i] + + Context(fmt.Sprintf("with quic version %d", version), func() { + It("gets a file when many outgoing packets are dropped", func() { + dropper := func(p PacketNumber) bool { + if p <= 5 { // don't interfere with the crypto handshake + return false + } + return p%4 == 0 + } + + iPort, _ := strconv.Atoi(port) + var err error + proxy, err = NewUDPProxy(proxyPort, "localhost", iPort, nil, dropper) + 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()) + }) + + It("gets a file when many incoming packets are dropped", func() { + dropper := func(p PacketNumber) bool { + if p <= 5 { // don't interfere with the crypto handshake + return false + } + return p%4 == 0 + } + + iPort, _ := strconv.Atoi(port) + var err error + proxy, err = NewUDPProxy(proxyPort, "localhost", iPort, dropper, nil) + 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()) + }) + + }) + } +}) diff --git a/integrationtests/integrationtests_suite_test.go b/integrationtests/integrationtests_suite_test.go index 7cf70023..0f365427 100644 --- a/integrationtests/integrationtests_suite_test.go +++ b/integrationtests/integrationtests_suite_test.go @@ -54,6 +54,7 @@ var _ = AfterSuite(func() { }) func setupHTTPHandlers() { + defer GinkgoRecover() data = make([]byte, dataLen) _, err := rand.Read(data) Expect(err).NotTo(HaveOccurred()) diff --git a/integrationtests/udp_proxy.go b/integrationtests/udp_proxy.go index 18947b9b..9322ea11 100644 --- a/integrationtests/udp_proxy.go +++ b/integrationtests/udp_proxy.go @@ -11,12 +11,12 @@ type connection struct { ClientAddr *net.UDPAddr // Address of the client ServerConn *net.UDPConn // UDP connection to server - incomingPacketCounter packetNumber - outgoingPacketCounter packetNumber + incomingPacketCounter PacketNumber + outgoingPacketCounter PacketNumber } -type packetNumber uint64 -type dropCallback func(packetNumber) bool +type PacketNumber uint64 +type dropCallback func(PacketNumber) bool // UDPProxy is a UDP proxy type UDPProxy struct { @@ -33,7 +33,7 @@ type UDPProxy struct { // NewUDPProxy creates a new UDP proxy func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket dropCallback) (*UDPProxy, error) { - dontDrop := func(p packetNumber) bool { + dontDrop := func(p PacketNumber) bool { return false } diff --git a/integrationtests/udp_proxy_test.go b/integrationtests/udp_proxy_test.go index 6bab2bec..04645360 100644 --- a/integrationtests/udp_proxy_test.go +++ b/integrationtests/udp_proxy_test.go @@ -114,13 +114,13 @@ var _ = Describe("Integrationtests", func() { var key string var conn *connection for key, conn = range proxy.clientDict { - Expect(conn.incomingPacketCounter).To(Equal(packetNumber(1))) + Expect(conn.incomingPacketCounter).To(Equal(PacketNumber(1))) } _, err = clientConn.Write([]byte("decafbad")) Expect(err).ToNot(HaveOccurred()) time.Sleep(time.Millisecond) Expect(proxy.clientDict).To(HaveLen(1)) - Expect(proxy.clientDict[key].incomingPacketCounter).To(Equal(packetNumber(2))) + Expect(proxy.clientDict[key].incomingPacketCounter).To(Equal(PacketNumber(2))) Expect(serverReceivedPackets).To(HaveLen(2)) Expect(serverReceivedPackets[0]).To(Equal(packetData("foobar"))) Expect(serverReceivedPackets[1]).To(Equal(packetData("decafbad"))) @@ -134,13 +134,13 @@ var _ = Describe("Integrationtests", func() { var key string var conn *connection for key, conn = range proxy.clientDict { - Expect(conn.outgoingPacketCounter).To(Equal(packetNumber(1))) + Expect(conn.outgoingPacketCounter).To(Equal(PacketNumber(1))) } _, err = clientConn.Write([]byte("decafbad")) Expect(err).ToNot(HaveOccurred()) time.Sleep(time.Millisecond) Expect(proxy.clientDict).To(HaveLen(1)) - Expect(proxy.clientDict[key].outgoingPacketCounter).To(Equal(packetNumber(2))) + Expect(proxy.clientDict[key].outgoingPacketCounter).To(Equal(PacketNumber(2))) var clientReceivedPackets []packetData @@ -170,7 +170,7 @@ var _ = Describe("Integrationtests", func() { Context("Drop Callbacks", func() { It("drops incoming packets", func() { - dropper := func(p packetNumber) bool { + dropper := func(p PacketNumber) bool { return p%2 == 0 } @@ -190,7 +190,7 @@ var _ = Describe("Integrationtests", func() { }) It("drops outgoing packets", func() { - dropper := func(p packetNumber) bool { + dropper := func(p PacketNumber) bool { return p%2 == 0 }