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