From 6ba193da7d070d9fd3948ba91cd8b277f16370f7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 9 Oct 2022 18:07:07 +0300 Subject: [PATCH] don't drop more than 10 consecutive packets in drop test --- integrationtests/self/handshake_drop_test.go | 38 +++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/integrationtests/self/handshake_drop_test.go b/integrationtests/self/handshake_drop_test.go index 2bd6e362514..32fcbb0414a 100644 --- a/integrationtests/self/handshake_drop_test.go +++ b/integrationtests/self/handshake_drop_test.go @@ -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) })