github.com/danielpfeifer02/quic-go-prio-packs@v0.41.0-28/internal/congestion/hybrid_slow_start_test.go (about)

     1  package congestion
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/danielpfeifer02/quic-go-prio-packs/internal/protocol"
     7  
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Hybrid slow start", func() {
    13  	var slowStart HybridSlowStart
    14  
    15  	BeforeEach(func() {
    16  		slowStart = HybridSlowStart{}
    17  	})
    18  
    19  	It("works in a simple case", func() {
    20  		packetNumber := protocol.PacketNumber(1)
    21  		endPacketNumber := protocol.PacketNumber(3)
    22  		slowStart.StartReceiveRound(endPacketNumber)
    23  
    24  		packetNumber++
    25  		Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse())
    26  
    27  		// Test duplicates.
    28  		Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse())
    29  
    30  		packetNumber++
    31  		Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse())
    32  		packetNumber++
    33  		Expect(slowStart.IsEndOfRound(packetNumber)).To(BeTrue())
    34  
    35  		// Test without a new registered end_packet_number;
    36  		packetNumber++
    37  		Expect(slowStart.IsEndOfRound(packetNumber)).To(BeTrue())
    38  
    39  		endPacketNumber = 20
    40  		slowStart.StartReceiveRound(endPacketNumber)
    41  		for packetNumber < endPacketNumber {
    42  			packetNumber++
    43  			Expect(slowStart.IsEndOfRound(packetNumber)).To(BeFalse())
    44  		}
    45  		packetNumber++
    46  		Expect(slowStart.IsEndOfRound(packetNumber)).To(BeTrue())
    47  	})
    48  
    49  	It("works with delay", func() {
    50  		rtt := 60 * time.Millisecond
    51  		// We expect to detect the increase at +1/8 of the RTT; hence at a typical
    52  		// RTT of 60ms the detection will happen at 67.5 ms.
    53  		const hybridStartMinSamples = 8 // Number of acks required to trigger.
    54  
    55  		endPacketNumber := protocol.PacketNumber(1)
    56  		endPacketNumber++
    57  		slowStart.StartReceiveRound(endPacketNumber)
    58  
    59  		// Will not trigger since our lowest RTT in our burst is the same as the long
    60  		// term RTT provided.
    61  		for n := 0; n < hybridStartMinSamples; n++ {
    62  			Expect(slowStart.ShouldExitSlowStart(rtt+time.Duration(n)*time.Millisecond, rtt, 100)).To(BeFalse())
    63  		}
    64  		endPacketNumber++
    65  		slowStart.StartReceiveRound(endPacketNumber)
    66  		for n := 1; n < hybridStartMinSamples; n++ {
    67  			Expect(slowStart.ShouldExitSlowStart(rtt+(time.Duration(n)+10)*time.Millisecond, rtt, 100)).To(BeFalse())
    68  		}
    69  		// Expect to trigger since all packets in this burst was above the long term
    70  		// RTT provided.
    71  		Expect(slowStart.ShouldExitSlowStart(rtt+10*time.Millisecond, rtt, 100)).To(BeTrue())
    72  	})
    73  })