From c337daf7db6b2f45306e9b972588478201259c0d Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 28 Nov 2023 09:19:54 -0800 Subject: [PATCH] quic: enable qlog output in tests Set QLOG=/some/dir to enable qlog logging in tests. Change-Id: Id4006c66fd555ad0ca47914d0af9f9ab46467c9c Reviewed-on: https://go-review.googlesource.com/c/net/+/550796 Reviewed-by: Jonathan Amsterdam LUCI-TryBot-Result: Go LUCI --- internal/quic/conn_test.go | 12 +++++++++++- internal/quic/endpoint_test.go | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/quic/conn_test.go b/internal/quic/conn_test.go index abf7eede7..ddf0740e2 100644 --- a/internal/quic/conn_test.go +++ b/internal/quic/conn_test.go @@ -13,15 +13,21 @@ import ( "errors" "flag" "fmt" + "log/slog" "math" "net/netip" "reflect" "strings" "testing" "time" + + "golang.org/x/net/internal/quic/qlog" ) -var testVV = flag.Bool("vv", false, "even more verbose test output") +var ( + testVV = flag.Bool("vv", false, "even more verbose test output") + qlogdir = flag.String("qlog", "", "write qlog logs to directory") +) func TestConnTestConn(t *testing.T) { tc := newTestConn(t, serverSide) @@ -199,6 +205,10 @@ func newTestConn(t *testing.T, side connSide, opts ...any) *testConn { config := &Config{ TLSConfig: newTestTLSConfig(side), StatelessResetKey: testStatelessResetKey, + QLogLogger: slog.New(qlog.NewJSONHandler(qlog.HandlerOptions{ + Level: QLogLevelFrame, + Dir: *qlogdir, + })), } var cids newServerConnIDs if side == serverSide { diff --git a/internal/quic/endpoint_test.go b/internal/quic/endpoint_test.go index 452d26052..ab6cd1cf5 100644 --- a/internal/quic/endpoint_test.go +++ b/internal/quic/endpoint_test.go @@ -11,10 +11,13 @@ import ( "context" "crypto/tls" "io" + "log/slog" "net" "net/netip" "testing" "time" + + "golang.org/x/net/internal/quic/qlog" ) func TestConnect(t *testing.T) { @@ -83,6 +86,12 @@ func newLocalEndpoint(t *testing.T, side connSide, conf *Config) *Endpoint { conf = &newConf conf.TLSConfig = newTestTLSConfig(side) } + if conf.QLogLogger == nil { + conf.QLogLogger = slog.New(qlog.NewJSONHandler(qlog.HandlerOptions{ + Level: QLogLevelFrame, + Dir: *qlogdir, + })) + } e, err := Listen("udp", "127.0.0.1:0", conf) if err != nil { t.Fatal(err)