forked from quic-go/quic-go
migrate the connection tests away from Ginkgo (#4823)
This commit is contained in:
@@ -974,7 +974,7 @@ func (s *connection) handleLongHeaderPacket(p receivedPacket, hdr *wire.Header)
|
||||
// drop 0-RTT packets, if we are a client
|
||||
if s.perspective == protocol.PerspectiveClient && hdr.Type == protocol.PacketType0RTT {
|
||||
if s.tracer != nil && s.tracer.DroppedPacket != nil {
|
||||
s.tracer.DroppedPacket(logging.PacketType0RTT, protocol.InvalidPacketNumber, p.Size(), logging.PacketDropKeyUnavailable)
|
||||
s.tracer.DroppedPacket(logging.PacketType0RTT, protocol.InvalidPacketNumber, p.Size(), logging.PacketDropUnexpectedPacket)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1084,14 +1084,6 @@ func (s *connection) handleRetryPacket(hdr *wire.Header, data []byte, rcvTime ti
|
||||
return false
|
||||
}
|
||||
|
||||
if s.logger.Debug() {
|
||||
s.logger.Debugf("<- Received Retry:")
|
||||
(&wire.ExtendedHeader{Header: *hdr}).Log(s.logger)
|
||||
s.logger.Debugf("Switching destination connection ID to: %s", hdr.SrcConnectionID)
|
||||
}
|
||||
if s.tracer != nil && s.tracer.ReceivedRetry != nil {
|
||||
s.tracer.ReceivedRetry(hdr)
|
||||
}
|
||||
newDestConnID := hdr.SrcConnectionID
|
||||
s.receivedRetry = true
|
||||
if err := s.sentPacketHandler.ResetForRetry(rcvTime); err != nil {
|
||||
@@ -1103,6 +1095,16 @@ func (s *connection) handleRetryPacket(hdr *wire.Header, data []byte, rcvTime ti
|
||||
s.cryptoStreamHandler.ChangeConnectionID(newDestConnID)
|
||||
s.packer.SetToken(hdr.Token)
|
||||
s.connIDManager.ChangeInitialConnID(newDestConnID)
|
||||
|
||||
if s.logger.Debug() {
|
||||
s.logger.Debugf("<- Received Retry:")
|
||||
(&wire.ExtendedHeader{Header: *hdr}).Log(s.logger)
|
||||
s.logger.Debugf("Switching destination connection ID to: %s", hdr.SrcConnectionID)
|
||||
}
|
||||
if s.tracer != nil && s.tracer.ReceivedRetry != nil {
|
||||
s.tracer.ReceivedRetry(hdr)
|
||||
}
|
||||
|
||||
s.scheduleSending()
|
||||
return true
|
||||
}
|
||||
@@ -1351,7 +1353,10 @@ func (s *connection) handleFrame(
|
||||
s.handlePathChallengeFrame(frame)
|
||||
case *wire.PathResponseFrame:
|
||||
// since we don't send PATH_CHALLENGEs, we don't expect PATH_RESPONSEs
|
||||
err = errors.New("unexpected PATH_RESPONSE frame")
|
||||
err = &qerr.TransportError{
|
||||
ErrorCode: qerr.ProtocolViolation,
|
||||
ErrorMessage: "unexpected PATH_RESPONSE frame",
|
||||
}
|
||||
case *wire.NewTokenFrame:
|
||||
err = s.handleNewTokenFrame(frame)
|
||||
case *wire.NewConnectionIDFrame:
|
||||
@@ -1452,9 +1457,7 @@ func (s *connection) handleStreamFrame(frame *wire.StreamFrame, rcvTime time.Tim
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if str == nil {
|
||||
// Stream is closed and already garbage collected
|
||||
// ignore this StreamFrame
|
||||
if str == nil { // stream was already closed and garbage collected
|
||||
return nil
|
||||
}
|
||||
return str.handleStreamFrame(frame, rcvTime)
|
||||
|
||||
@@ -125,12 +125,7 @@ func (s *connection) logShortHeaderPacket(
|
||||
ack = toLoggingAckFrame(ackFrame)
|
||||
}
|
||||
s.tracer.SentShortHeaderPacket(
|
||||
&logging.ShortHeader{
|
||||
DestConnectionID: destConnID,
|
||||
PacketNumber: pn,
|
||||
PacketNumberLen: pnLen,
|
||||
KeyPhase: kp,
|
||||
},
|
||||
&logging.ShortHeader{DestConnectionID: destConnID, PacketNumber: pn, PacketNumberLen: pnLen, KeyPhase: kp},
|
||||
size,
|
||||
ecn,
|
||||
ack,
|
||||
|
||||
@@ -1,52 +1,72 @@
|
||||
package quic
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/wire"
|
||||
"github.com/quic-go/quic-go/logging"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var _ = Describe("CRYPTO frame", func() {
|
||||
It("converts CRYPTO frames", func() {
|
||||
f := toLoggingFrame(&wire.CryptoFrame{
|
||||
Offset: 1234,
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
Expect(f).To(BeAssignableToTypeOf(&logging.CryptoFrame{}))
|
||||
cf := f.(*logging.CryptoFrame)
|
||||
Expect(cf.Offset).To(Equal(logging.ByteCount(1234)))
|
||||
Expect(cf.Length).To(Equal(logging.ByteCount(6)))
|
||||
func TestConnectionLoggingCryptoFrame(t *testing.T) {
|
||||
f := toLoggingFrame(&wire.CryptoFrame{
|
||||
Offset: 1234,
|
||||
Data: []byte("foobar"),
|
||||
})
|
||||
require.Equal(t, &logging.CryptoFrame{
|
||||
Offset: 1234,
|
||||
Length: 6,
|
||||
}, f)
|
||||
}
|
||||
|
||||
It("converts STREAM frames", func() {
|
||||
f := toLoggingFrame(&wire.StreamFrame{
|
||||
StreamID: 42,
|
||||
Offset: 1234,
|
||||
Data: []byte("foo"),
|
||||
Fin: true,
|
||||
})
|
||||
Expect(f).To(BeAssignableToTypeOf(&logging.StreamFrame{}))
|
||||
sf := f.(*logging.StreamFrame)
|
||||
Expect(sf.StreamID).To(Equal(logging.StreamID(42)))
|
||||
Expect(sf.Offset).To(Equal(logging.ByteCount(1234)))
|
||||
Expect(sf.Length).To(Equal(logging.ByteCount(3)))
|
||||
Expect(sf.Fin).To(BeTrue())
|
||||
func TestConnectionLoggingStreamFrame(t *testing.T) {
|
||||
f := toLoggingFrame(&wire.StreamFrame{
|
||||
StreamID: 42,
|
||||
Offset: 1234,
|
||||
Data: []byte("foo"),
|
||||
Fin: true,
|
||||
})
|
||||
require.Equal(t, &logging.StreamFrame{
|
||||
StreamID: 42,
|
||||
Offset: 1234,
|
||||
Length: 3,
|
||||
Fin: true,
|
||||
}, f)
|
||||
}
|
||||
|
||||
It("converts DATAGRAM frames", func() {
|
||||
f := toLoggingFrame(&wire.DatagramFrame{Data: []byte("foobar")})
|
||||
Expect(f).To(BeAssignableToTypeOf(&logging.DatagramFrame{}))
|
||||
df := f.(*logging.DatagramFrame)
|
||||
Expect(df.Length).To(Equal(logging.ByteCount(6)))
|
||||
})
|
||||
func TestConnectionLoggingAckFrame(t *testing.T) {
|
||||
ack := &wire.AckFrame{
|
||||
AckRanges: []wire.AckRange{
|
||||
{Smallest: 1, Largest: 3},
|
||||
{Smallest: 6, Largest: 7},
|
||||
},
|
||||
DelayTime: 42,
|
||||
ECNCE: 123,
|
||||
ECT0: 456,
|
||||
ECT1: 789,
|
||||
}
|
||||
f := toLoggingFrame(ack)
|
||||
// now modify the ACK range in the original frame
|
||||
ack.AckRanges[0].Smallest = 2
|
||||
require.Equal(t, &logging.AckFrame{
|
||||
AckRanges: []wire.AckRange{
|
||||
{Smallest: 1, Largest: 3}, // unchanged, since the ACK ranges were cloned
|
||||
{Smallest: 6, Largest: 7},
|
||||
},
|
||||
DelayTime: 42,
|
||||
ECNCE: 123,
|
||||
ECT0: 456,
|
||||
ECT1: 789,
|
||||
}, f)
|
||||
}
|
||||
|
||||
It("converts other frames", func() {
|
||||
f := toLoggingFrame(&wire.MaxDataFrame{MaximumData: 1234})
|
||||
Expect(f).To(BeAssignableToTypeOf(&logging.MaxDataFrame{}))
|
||||
Expect(f).ToNot(BeAssignableToTypeOf(&logging.MaxStreamDataFrame{}))
|
||||
mdf := f.(*logging.MaxDataFrame)
|
||||
Expect(mdf.MaximumData).To(Equal(logging.ByteCount(1234)))
|
||||
})
|
||||
})
|
||||
func TestConnectionLoggingDatagramFrame(t *testing.T) {
|
||||
f := toLoggingFrame(&wire.DatagramFrame{Data: []byte("foobar")})
|
||||
require.Equal(t, &logging.DatagramFrame{Length: 6}, f)
|
||||
}
|
||||
|
||||
func TestConnectionLoggingOtherFrames(t *testing.T) {
|
||||
f := toLoggingFrame(&wire.MaxDataFrame{MaximumData: 1234})
|
||||
require.Equal(t, &logging.MaxDataFrame{MaximumData: 1234}, f)
|
||||
}
|
||||
|
||||
5808
connection_test.go
5808
connection_test.go
File diff suppressed because it is too large
Load Diff
@@ -1,62 +1,60 @@
|
||||
package quic
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func (t *connectionTimer) Deadline() time.Time { return t.timer.Deadline() }
|
||||
|
||||
var _ = Describe("Timer", func() {
|
||||
It("sets an idle timeout", func() {
|
||||
now := time.Now()
|
||||
t := newTimer()
|
||||
t.SetTimer(now.Add(time.Hour), time.Time{}, time.Time{}, time.Time{})
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Hour)))
|
||||
func TestConnectionTimerModes(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
t.Run("idle timeout", func(t *testing.T) {
|
||||
timer := newTimer()
|
||||
timer.SetTimer(now.Add(time.Hour), time.Time{}, time.Time{}, time.Time{})
|
||||
require.Equal(t, now.Add(time.Hour), timer.Deadline())
|
||||
})
|
||||
|
||||
It("sets an ACK timer", func() {
|
||||
now := time.Now()
|
||||
t := newTimer()
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Minute)))
|
||||
t.Run("ACK timer", func(t *testing.T) {
|
||||
timer := newTimer()
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
require.Equal(t, now.Add(time.Minute), timer.Deadline())
|
||||
})
|
||||
|
||||
It("sets a loss timer", func() {
|
||||
now := time.Now()
|
||||
t := newTimer()
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), time.Time{})
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Second)))
|
||||
t.Run("loss timer", func(t *testing.T) {
|
||||
timer := newTimer()
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), time.Time{})
|
||||
require.Equal(t, now.Add(time.Second), timer.Deadline())
|
||||
})
|
||||
|
||||
It("sets a pacing timer", func() {
|
||||
now := time.Now()
|
||||
t := newTimer()
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), now.Add(time.Millisecond))
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Millisecond)))
|
||||
t.Run("pacing timer", func(t *testing.T) {
|
||||
timer := newTimer()
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), now.Add(time.Millisecond))
|
||||
require.Equal(t, now.Add(time.Millisecond), timer.Deadline())
|
||||
})
|
||||
}
|
||||
|
||||
It("doesn't reset to an earlier time", func() {
|
||||
now := time.Now()
|
||||
t := newTimer()
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Minute)))
|
||||
t.SetRead()
|
||||
func TestConnectionTimerReset(t *testing.T) {
|
||||
now := time.Now()
|
||||
timer := newTimer()
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
require.Equal(t, now.Add(time.Minute), timer.Deadline())
|
||||
timer.SetRead()
|
||||
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Hour)))
|
||||
})
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
require.Equal(t, now.Add(time.Hour), timer.Deadline())
|
||||
}
|
||||
|
||||
It("allows the pacing timer to be set to send immediately", func() {
|
||||
now := time.Now()
|
||||
t := newTimer()
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
Expect(t.Deadline()).To(Equal(now.Add(time.Minute)))
|
||||
t.SetRead()
|
||||
func TestConnectionTimerSendImmediately(t *testing.T) {
|
||||
now := time.Now()
|
||||
timer := newTimer()
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
|
||||
require.Equal(t, now.Add(time.Minute), timer.Deadline())
|
||||
timer.SetRead()
|
||||
|
||||
t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, deadlineSendImmediately)
|
||||
Expect(t.Deadline()).To(Equal(deadlineSendImmediately))
|
||||
})
|
||||
})
|
||||
timer.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, deadlineSendImmediately)
|
||||
require.Equal(t, deadlineSendImmediately, timer.Deadline())
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package quic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
@@ -59,6 +60,12 @@ func newUPDConnLocalhost(t testing.TB) *net.UDPConn {
|
||||
return conn
|
||||
}
|
||||
|
||||
func areConnsRunning() bool {
|
||||
var b bytes.Buffer
|
||||
pprof.Lookup("goroutine").WriteTo(&b, 1)
|
||||
return strings.Contains(b.String(), "quic-go.(*connection).run")
|
||||
}
|
||||
|
||||
func areServersRunning() bool {
|
||||
var b bytes.Buffer
|
||||
pprof.Lookup("goroutine").WriteTo(&b, 1)
|
||||
@@ -76,3 +83,19 @@ var _ = AfterEach(func() {
|
||||
Eventually(areServersRunning).Should(BeFalse())
|
||||
Eventually(areTransportsRunning()).Should(BeFalse())
|
||||
})
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
status := m.Run()
|
||||
if status != 0 {
|
||||
os.Exit(status)
|
||||
}
|
||||
if areConnsRunning() {
|
||||
fmt.Println("stray connection goroutines found")
|
||||
os.Exit(1)
|
||||
}
|
||||
if areTransportsRunning() {
|
||||
fmt.Println("stray transport goroutines found")
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(status)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func getPacketWithPacketType(t *testing.T, connID protocol.ConnectionID, typ pro
|
||||
PacketNumberLen: protocol.PacketNumberLen2,
|
||||
}).Append(nil, protocol.Version1)
|
||||
require.NoError(t, err)
|
||||
return b
|
||||
return append(b, bytes.Repeat([]byte{42}, int(length)-2)...)
|
||||
}
|
||||
|
||||
func TestTransportPacketHandling(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user