Skip to content

Commit

Permalink
quic: enable qlog output in tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
neild committed Dec 19, 2023
1 parent 2b416c3 commit c337daf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/quic/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions internal/quic/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c337daf

Please sign in to comment.