Skip to content

Commit

Permalink
don't drop more than 10 consecutive packets in drop test (#3584)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 11, 2022
1 parent ee013d9 commit 192ae34
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions integrationtests/self/handshake_drop_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"io"
mrand "math/rand"
"net"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -62,10 +63,6 @@ var _ = Describe("Handshake drop tests", func() {
Expect(err).ToNot(HaveOccurred())
}

stochasticDropper := func(freq int) bool {
return mrand.Int63n(int64(freq)) == 0
}

clientSpeaksFirst := &applicationProtocol{
name: "client speaks first",
run: func(version protocol.VersionNumber) {
Expand Down Expand Up @@ -232,8 +229,39 @@ var _ = Describe("Handshake drop tests", func() {
})

It(fmt.Sprintf("establishes a connection when 1/3 of the packets are lost in %s direction", direction), func() {
const maxSequentiallyDropped = 10
var mx sync.Mutex
var incoming, outgoing int

startListenerAndProxy(func(d quicproxy.Direction, _ []byte) bool {
return d.Is(direction) && stochasticDropper(3)
drop := mrand.Int63n(int64(3)) == 0

mx.Lock()
defer mx.Unlock()
// never drop more than 10 consecutive packets
if d.Is(quicproxy.DirectionIncoming) {
if drop {
incoming++
if incoming > maxSequentiallyDropped {
drop = false
}
}
if !drop {
incoming = 0
}
}
if d.Is(quicproxy.DirectionOutgoing) {
if drop {
outgoing++
if outgoing > maxSequentiallyDropped {
drop = false
}
}
if !drop {
outgoing = 0
}
}
return drop
}, doRetry, longCertChain, version)
app.run(version)
})
Expand Down

0 comments on commit 192ae34

Please sign in to comment.