improve timeout measurement in the timeout test

When not sending any packets, the idle timeout starts when receiving the
HANDSHAKE_DONE frame (on the client side), not when the handshake completes.
This commit is contained in:
Marten Seemann 2021-02-15 14:08:21 +08:00
parent 7ee88def4a
commit 11c5c548b6

View file

@ -15,7 +15,9 @@ import (
quic "github.com/lucas-clemente/quic-go" quic "github.com/lucas-clemente/quic-go"
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy" 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/internal/utils"
"github.com/lucas-clemente/quic-go/logging"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@ -44,6 +46,17 @@ func (c *faultyConn) WriteTo(p []byte, addr net.Addr) (int, error) {
return 0, io.ErrClosedPipe 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 { func areHandshakesRunning() bool {
var b bytes.Buffer var b bytes.Buffer
pprof.Lookup("goroutine").WriteTo(&b, 1) pprof.Lookup("goroutine").WriteTo(&b, 1)
@ -201,13 +214,13 @@ var _ = Describe("Timeout tests", func() {
close(serverSessionClosed) close(serverSessionClosed)
}() }()
tr := &handshakeCompleteTracer{}
sess, err := quic.DialAddr( sess, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port), fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(), getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIdleTimeout: idleTimeout}), getQuicConfig(&quic.Config{MaxIdleTimeout: idleTimeout, Tracer: newTracer(func() logging.ConnectionTracer { return tr })}),
) )
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
startTime := time.Now()
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
defer GinkgoRecover() defer GinkgoRecover()
@ -216,7 +229,8 @@ var _ = Describe("Timeout tests", func() {
close(done) close(done)
}() }()
Eventually(done, 2*idleTimeout).Should(BeClosed()) Eventually(done, 2*idleTimeout).Should(BeClosed())
dur := time.Since(startTime) Expect(tr.completionTime).ToNot(BeZero())
dur := time.Since(tr.completionTime)
Expect(dur).To(And( Expect(dur).To(And(
BeNumerically(">=", idleTimeout), BeNumerically(">=", idleTimeout),
BeNumerically("<", idleTimeout*6/5), BeNumerically("<", idleTimeout*6/5),