diff --git a/integrationtests/self/self_suite_test.go b/integrationtests/self/self_suite_test.go index 81956cbf..c3ff6454 100644 --- a/integrationtests/self/self_suite_test.go +++ b/integrationtests/self/self_suite_test.go @@ -23,6 +23,7 @@ import ( "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/internal/utils" + "github.com/lucas-clemente/quic-go/internal/wire" "github.com/lucas-clemente/quic-go/logging" "github.com/lucas-clemente/quic-go/qlog" @@ -368,6 +369,43 @@ func (t *connTracer) LossTimerCanceled() func (t *connTracer) Debug(string, string) {} func (t *connTracer) Close() {} +type packet struct { + time time.Time + hdr *logging.ExtendedHeader + frames []logging.Frame +} + +type packetTracer struct { + connTracer + closed chan struct{} + sent, rcvd []packet +} + +func newPacketTracer() *packetTracer { + return &packetTracer{closed: make(chan struct{})} +} + +func (t *packetTracer) ReceivedPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, frames []logging.Frame) { + t.rcvd = append(t.rcvd, packet{time: time.Now(), hdr: hdr, frames: frames}) +} + +func (t *packetTracer) SentPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, ack *wire.AckFrame, frames []logging.Frame) { + if ack != nil { + frames = append(frames, ack) + } + t.sent = append(t.sent, packet{time: time.Now(), hdr: hdr, frames: frames}) +} +func (t *packetTracer) Close() { close(t.closed) } +func (t *packetTracer) getSentPackets() []packet { + <-t.closed + return t.sent +} + +func (t *packetTracer) getRcvdPackets() []packet { + <-t.closed + return t.rcvd +} + func TestSelf(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Self integration tests") diff --git a/integrationtests/self/timeout_test.go b/integrationtests/self/timeout_test.go index e312b9ba..6c660e10 100644 --- a/integrationtests/self/timeout_test.go +++ b/integrationtests/self/timeout_test.go @@ -15,7 +15,6 @@ import ( quic "github.com/lucas-clemente/quic-go" quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy" - "github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/logging" . "github.com/onsi/ginkgo" @@ -46,17 +45,6 @@ func (c *faultyConn) WriteTo(p []byte, addr net.Addr) (int, error) { return 0, io.ErrClosedPipe } -type handshakeCompleteTracer struct { - connTracer - completionTime time.Time -} - -func (t *handshakeCompleteTracer) DroppedEncryptionLevel(l protocol.EncryptionLevel) { - if l == protocol.EncryptionHandshake { - t.completionTime = time.Now() - } -} - func areHandshakesRunning() bool { var b bytes.Buffer pprof.Lookup("goroutine").WriteTo(&b, 1) @@ -214,7 +202,7 @@ var _ = Describe("Timeout tests", func() { close(serverSessionClosed) }() - tr := &handshakeCompleteTracer{} + tr := newPacketTracer() sess, err := quic.DialAddr( fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), getTLSClientConfig(), @@ -233,9 +221,26 @@ var _ = Describe("Timeout tests", func() { close(done) }() Eventually(done, 2*idleTimeout).Should(BeClosed()) - Expect(tr.completionTime).ToNot(BeZero()) - dur := time.Since(tr.completionTime) - Expect(dur).To(And( + var lastAckElicitingPacketSentAt time.Time + for _, p := range tr.getSentPackets() { + var hasAckElicitingFrame bool + for _, f := range p.frames { + if _, ok := f.(*logging.AckFrame); ok { + continue + } + hasAckElicitingFrame = true + break + } + if hasAckElicitingFrame { + lastAckElicitingPacketSentAt = p.time + } + } + rcvdPackets := tr.getRcvdPackets() + lastPacketRcvdAt := rcvdPackets[len(rcvdPackets)-1].time + // We're ignoring here that only the first ack-eliciting packet sent resets the idle timeout. + // This is ok since we're dealing with a lossless connection here, + // and we'd expect to receive an ACK for additional other ack-eliciting packet sent. + Expect(time.Since(utils.MaxTime(lastAckElicitingPacketSentAt, lastPacketRcvdAt))).To(And( BeNumerically(">=", idleTimeout), BeNumerically("<", idleTimeout*6/5), )) diff --git a/integrationtests/self/zero_rtt_test.go b/integrationtests/self/zero_rtt_test.go index 39da5dce..4cb2ec72 100644 --- a/integrationtests/self/zero_rtt_test.go +++ b/integrationtests/self/zero_rtt_test.go @@ -23,41 +23,6 @@ import ( . "github.com/onsi/gomega" ) -type packet struct { - time time.Time - hdr *logging.ExtendedHeader - frames []logging.Frame -} - -type packetTracer struct { - connTracer - closed chan struct{} - sent, rcvd []packet -} - -func newPacketTracer() *packetTracer { - return &packetTracer{closed: make(chan struct{})} -} - -func (t *packetTracer) ReceivedPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, frames []logging.Frame) { - t.rcvd = append(t.rcvd, packet{time: time.Now(), hdr: hdr, frames: frames}) -} -func (t *packetTracer) SentPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, ack *wire.AckFrame, frames []logging.Frame) { - if ack != nil { - frames = append(frames, ack) - } - t.sent = append(t.sent, packet{time: time.Now(), hdr: hdr, frames: frames}) -} -func (t *packetTracer) Close() { close(t.closed) } -func (t *packetTracer) getSentPackets() []packet { - <-t.closed - return t.sent -} -func (t *packetTracer) getRcvdPackets() []packet { - <-t.closed - return t.rcvd -} - var _ = Describe("0-RTT", func() { rtt := scaleDuration(5 * time.Millisecond)