forked from quic-go/quic-go
add an integration test for dropped packets during the handshake
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
. "github.com/onsi/gomega/gbytes"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,14 +23,16 @@ var directions = []quicproxy.Direction{quicproxy.DirectionIncoming, quicproxy.Di
|
|||||||
var _ = Describe("Drop tests", func() {
|
var _ = Describe("Drop tests", func() {
|
||||||
var proxy *quicproxy.QuicProxy
|
var proxy *quicproxy.QuicProxy
|
||||||
|
|
||||||
runDropTest := func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber) {
|
startProxy := func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber) {
|
||||||
var err error
|
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(),
|
RemoteAddr: "localhost:" + testserver.Port(),
|
||||||
DropPacket: dropCallback,
|
DropPacket: dropCallback,
|
||||||
})
|
})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadFile := func(version protocol.VersionNumber) {
|
||||||
command := exec.Command(
|
command := exec.Command(
|
||||||
clientPath,
|
clientPath,
|
||||||
"--quic-version="+strconv.Itoa(int(version)),
|
"--quic-version="+strconv.Itoa(int(version)),
|
||||||
@@ -37,7 +40,6 @@ var _ = Describe("Drop tests", func() {
|
|||||||
"--port="+strconv.Itoa(proxy.LocalPort()),
|
"--port="+strconv.Itoa(proxy.LocalPort()),
|
||||||
"https://quic.clemente.io/prdata",
|
"https://quic.clemente.io/prdata",
|
||||||
)
|
)
|
||||||
|
|
||||||
session, err := Start(command, nil, GinkgoWriter)
|
session, err := Start(command, nil, GinkgoWriter)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
defer session.Kill()
|
defer session.Kill()
|
||||||
@@ -45,51 +47,91 @@ var _ = Describe("Drop tests", func() {
|
|||||||
Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue())
|
Expect(bytes.Contains(session.Out.Contents(), testserver.PRData)).To(BeTrue())
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterEach(func() {
|
downloadHello := func(version protocol.VersionNumber) {
|
||||||
Expect(proxy.Close()).To(Succeed())
|
command := exec.Command(
|
||||||
})
|
clientPath,
|
||||||
|
"--quic-version="+strconv.Itoa(int(version)),
|
||||||
Context("after the crypto handshake", func() {
|
"--host=127.0.0.1",
|
||||||
deterministicDropper := func(p, interval, dropInARow uint64) bool {
|
"--port="+strconv.Itoa(proxy.LocalPort()),
|
||||||
if p <= 10 { // don't interfere with the crypto handshake
|
"https://quic.clemente.io/hello",
|
||||||
return false
|
)
|
||||||
|
session, err := Start(command, nil, GinkgoWriter)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
defer session.Kill()
|
||||||
|
Eventually(session, 20).Should(Exit(0))
|
||||||
|
Expect(session.Out).To(Say(":status 200"))
|
||||||
|
Expect(session.Out).To(Say("body: Hello, World!\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deterministicDropper := func(p, interval, dropInARow uint64) bool {
|
||||||
return (p % interval) < dropInARow
|
return (p % interval) < dropInARow
|
||||||
}
|
}
|
||||||
|
|
||||||
stochasticDropper := func(p protocol.PacketNumber, freq int) bool {
|
stochasticDropper := func(freq int) bool {
|
||||||
if p <= 10 { // don't interfere with the crypto handshake
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return mrand.Int63n(int64(freq)) == 0
|
return mrand.Int63n(int64(freq)) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
Expect(proxy.Close()).To(Succeed())
|
||||||
|
})
|
||||||
|
|
||||||
for _, v := range protocol.SupportedVersions {
|
for _, v := range protocol.SupportedVersions {
|
||||||
version := v
|
version := v
|
||||||
|
|
||||||
Context(fmt.Sprintf("with QUIC version %d", version), func() {
|
Context(fmt.Sprintf("with QUIC version %d", version), func() {
|
||||||
|
Context("during the crypto handshake", func() {
|
||||||
|
for _, d := range directions {
|
||||||
|
direction := d
|
||||||
|
|
||||||
|
It(fmt.Sprintf("establishes a connection when the first packet is lost in %s direction", d), func() {
|
||||||
|
startProxy(func(d quicproxy.Direction, p uint64) bool {
|
||||||
|
return p == 1 && d.Is(direction)
|
||||||
|
}, version)
|
||||||
|
downloadHello(version)
|
||||||
|
})
|
||||||
|
|
||||||
|
It(fmt.Sprintf("establishes a connection when the second packet is lost in %s direction", d), func() {
|
||||||
|
startProxy(func(d quicproxy.Direction, p uint64) bool {
|
||||||
|
return p == 2 && d.Is(direction)
|
||||||
|
}, version)
|
||||||
|
downloadHello(version)
|
||||||
|
})
|
||||||
|
|
||||||
|
It(fmt.Sprintf("establishes a connection when 1/5 of the packets are lost in %s direction", d), func() {
|
||||||
|
startProxy(func(d quicproxy.Direction, p uint64) bool {
|
||||||
|
return d.Is(direction) && stochasticDropper(5)
|
||||||
|
}, version)
|
||||||
|
downloadHello(version)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Context("after the crypto handshake", func() {
|
||||||
for _, d := range directions {
|
for _, d := range directions {
|
||||||
direction := d
|
direction := d
|
||||||
|
|
||||||
It(fmt.Sprintf("downloads a file when every 5th packet is dropped in %s direction", d), func() {
|
It(fmt.Sprintf("downloads a file when every 5th packet is dropped in %s direction", d), func() {
|
||||||
runDropTest(func(d quicproxy.Direction, p uint64) bool {
|
startProxy(func(d quicproxy.Direction, p uint64) bool {
|
||||||
return d.Is(direction) && deterministicDropper(p, 5, 1)
|
return p >= 10 && d.Is(direction) && deterministicDropper(p, 5, 1)
|
||||||
}, version)
|
}, version)
|
||||||
|
downloadFile(version)
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("downloads a file when 1/5th of all packet are dropped randomly in %s direction", d), func() {
|
It(fmt.Sprintf("downloads a file when 1/5th of all packet are dropped randomly in %s direction", d), func() {
|
||||||
runDropTest(func(d quicproxy.Direction, p protocol.PacketNumber) bool {
|
startProxy(func(d quicproxy.Direction, p uint64) bool {
|
||||||
return d.Is(direction) && stochasticDropper(p, 5)
|
return p >= 10 && d.Is(direction) && stochasticDropper(5)
|
||||||
}, version)
|
}, version)
|
||||||
|
downloadFile(version)
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("downloads a file when 10 packets every 100 packet are dropped in %s direction", d), func() {
|
It(fmt.Sprintf("downloads a file when 10 packets every 100 packet are dropped in %s direction", d), func() {
|
||||||
runDropTest(func(d quicproxy.Direction, p uint64) bool {
|
startProxy(func(d quicproxy.Direction, p uint64) bool {
|
||||||
return d.Is(direction) && deterministicDropper(p, 100, 10)
|
return p >= 10 && d.Is(direction) && deterministicDropper(p, 100, 10)
|
||||||
}, version)
|
}, version)
|
||||||
|
downloadFile(version)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user