Skip to content

Commit c337daf

Browse files
committed
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 <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 2b416c3 commit c337daf

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

internal/quic/conn_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@ import (
1313
"errors"
1414
"flag"
1515
"fmt"
16+
"log/slog"
1617
"math"
1718
"net/netip"
1819
"reflect"
1920
"strings"
2021
"testing"
2122
"time"
23+
24+
"golang.org/x/net/internal/quic/qlog"
2225
)
2326

24-
var testVV = flag.Bool("vv", false, "even more verbose test output")
27+
var (
28+
testVV = flag.Bool("vv", false, "even more verbose test output")
29+
qlogdir = flag.String("qlog", "", "write qlog logs to directory")
30+
)
2531

2632
func TestConnTestConn(t *testing.T) {
2733
tc := newTestConn(t, serverSide)
@@ -199,6 +205,10 @@ func newTestConn(t *testing.T, side connSide, opts ...any) *testConn {
199205
config := &Config{
200206
TLSConfig: newTestTLSConfig(side),
201207
StatelessResetKey: testStatelessResetKey,
208+
QLogLogger: slog.New(qlog.NewJSONHandler(qlog.HandlerOptions{
209+
Level: QLogLevelFrame,
210+
Dir: *qlogdir,
211+
})),
202212
}
203213
var cids newServerConnIDs
204214
if side == serverSide {

internal/quic/endpoint_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import (
1111
"context"
1212
"crypto/tls"
1313
"io"
14+
"log/slog"
1415
"net"
1516
"net/netip"
1617
"testing"
1718
"time"
19+
20+
"golang.org/x/net/internal/quic/qlog"
1821
)
1922

2023
func TestConnect(t *testing.T) {
@@ -83,6 +86,12 @@ func newLocalEndpoint(t *testing.T, side connSide, conf *Config) *Endpoint {
8386
conf = &newConf
8487
conf.TLSConfig = newTestTLSConfig(side)
8588
}
89+
if conf.QLogLogger == nil {
90+
conf.QLogLogger = slog.New(qlog.NewJSONHandler(qlog.HandlerOptions{
91+
Level: QLogLevelFrame,
92+
Dir: *qlogdir,
93+
}))
94+
}
8695
e, err := Listen("udp", "127.0.0.1:0", conf)
8796
if err != nil {
8897
t.Fatal(err)

0 commit comments

Comments
 (0)