forked from quic-go/quic-go
don't drop more than 10 consecutive packets in drop test (#3584)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
mrand "math/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -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) {
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user