From e354463e64f563d36f47130a477d3cfd106bffc8 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 30 May 2025 10:54:48 +0800 Subject: [PATCH] http3: use actual QUIC connection in frames tests (#5165) * http3: use actual QUIC connection in frames tests * wait for handshake completion --- http3/frames_test.go | 21 +++++++++++++++------ http3/http3_helper_test.go | 10 ++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/http3/frames_test.go b/http3/frames_test.go index 90582c7f..f8e20f33 100644 --- a/http3/frames_test.go +++ b/http3/frames_test.go @@ -2,17 +2,17 @@ package http3 import ( "bytes" + "context" "fmt" "io" "testing" + "time" "github.com/quic-go/quic-go" - mockquic "github.com/quic-go/quic-go/internal/mocks/quic" "github.com/quic-go/quic-go/quicvarint" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) func testFrameParserEOF(t *testing.T, data []byte) { @@ -30,20 +30,29 @@ func testFrameParserEOF(t *testing.T, data []byte) { func TestParserReservedFrameType(t *testing.T) { for _, ft := range []uint64{0x2, 0x6, 0x8, 0x9} { t.Run(fmt.Sprintf("type %#x", ft), func(t *testing.T) { - mockCtrl := gomock.NewController(t) - conn := mockquic.NewMockEarlyConnection(mockCtrl) + client, server := newConnPair(t) + data := quicvarint.Append(nil, ft) data = quicvarint.Append(data, 6) data = append(data, []byte("foobar")...) - conn.EXPECT().CloseWithError(quic.ApplicationErrorCode(ErrCodeFrameUnexpected), gomock.Any()) fp := frameParser{ r: bytes.NewReader(data), - conn: conn, + conn: client, } _, err := fp.ParseNext() require.Error(t, err) require.ErrorContains(t, err, "http3: reserved frame type") + + select { + case <-server.Context().Done(): + require.ErrorIs(t, + context.Cause(server.Context()), + &quic.ApplicationError{Remote: true, ErrorCode: quic.ApplicationErrorCode(ErrCodeFrameUnexpected)}, + ) + case <-time.After(time.Second): + t.Fatal("timeout") + } }) } } diff --git a/http3/http3_helper_test.go b/http3/http3_helper_test.go index 964f0c18..eff6196c 100644 --- a/http3/http3_helper_test.go +++ b/http3/http3_helper_test.go @@ -94,6 +94,11 @@ func newConnPair(t *testing.T) (client, server quic.EarlyConnection) { conn, err := ln.Accept(ctx) require.NoError(t, err) t.Cleanup(func() { conn.CloseWithError(0, "") }) + select { + case <-conn.HandshakeComplete(): + case <-ctx.Done(): + t.Fatal("timeout") + } return cl, conn } @@ -120,6 +125,11 @@ func newConnPairWithDatagrams(t *testing.T) (client, server quic.EarlyConnection conn, err := ln.Accept(ctx) require.NoError(t, err) t.Cleanup(func() { conn.CloseWithError(0, "") }) + select { + case <-conn.HandshakeComplete(): + case <-ctx.Done(): + t.Fatal("timeout") + } return cl, conn }