Skip to content

Commit

Permalink
remove custom qlogger implementation in tests (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Apr 25, 2024
1 parent ba7c5ff commit 0da5b74
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions webtransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"net"
"net/http"
"os"
"strconv"
"strings"
"sync"
Expand All @@ -20,35 +19,11 @@ import (

"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
"github.com/quic-go/quic-go/logging"
"github.com/quic-go/quic-go/qlog"

"github.com/stretchr/testify/require"
)

// create a qlog file in QLOGDIR, if that environment variable is set
func getQlogger(t *testing.T) func(context.Context, logging.Perspective, quic.ConnectionID) *logging.ConnectionTracer {
tracer := func(ctx context.Context, p logging.Perspective, connID quic.ConnectionID) *logging.ConnectionTracer {
qlogDir := os.Getenv("QLOGDIR")
if qlogDir == "" {
return nil
}
if _, err := os.Stat(qlogDir); os.IsNotExist(err) {
require.NoError(t, os.MkdirAll(qlogDir, 0755))
}
role := "server"
if p == logging.PerspectiveClient {
role = "client"
}
filename := fmt.Sprintf("./%s/log_%x_%s.qlog", qlogDir, connID, role)
t.Log("creating", filename)
f, err := os.Create(filename)
require.NoError(t, err)
return qlog.NewConnectionTracer(f, p, connID)
}
return tracer
}

func runServer(t *testing.T, s *webtransport.Server) (addr *net.UDPAddr, close func()) {
laddr, err := net.ResolveUDPAddr("udp", "localhost:0")
require.NoError(t, err)
Expand All @@ -71,15 +46,15 @@ func establishSession(t *testing.T, handler func(*webtransport.Session)) (sess *
s := &webtransport.Server{
H3: http3.Server{
TLSConfig: tlsConf,
QUICConfig: &quic.Config{Tracer: getQlogger(t), EnableDatagrams: true},
QUICConfig: &quic.Config{Tracer: qlog.DefaultTracer, EnableDatagrams: true},
},
}
addHandler(t, s, handler)

addr, closeServer := runServer(t, s)
d := webtransport.Dialer{
TLSClientConfig: &tls.Config{RootCAs: certPool},
QUICConfig: &quic.Config{Tracer: getQlogger(t), EnableDatagrams: true},
QUICConfig: &quic.Config{Tracer: qlog.DefaultTracer, EnableDatagrams: true},
}
defer d.Close()
url := fmt.Sprintf("https://localhost:%d/webtransport", addr.Port)
Expand Down Expand Up @@ -341,7 +316,7 @@ func TestMultipleClients(t *testing.T) {
defer wg.Done()
d := webtransport.Dialer{
TLSClientConfig: &tls.Config{RootCAs: certPool},
QUICConfig: &quic.Config{Tracer: getQlogger(t), EnableDatagrams: true},
QUICConfig: &quic.Config{Tracer: qlog.DefaultTracer, EnableDatagrams: true},
}
defer d.Close()
url := fmt.Sprintf("https://localhost:%d/webtransport", addr.Port)
Expand Down Expand Up @@ -531,7 +506,7 @@ func TestCheckOrigin(t *testing.T) {

d := webtransport.Dialer{
TLSClientConfig: &tls.Config{RootCAs: certPool},
QUICConfig: &quic.Config{Tracer: getQlogger(t), EnableDatagrams: true},
QUICConfig: &quic.Config{Tracer: qlog.DefaultTracer, EnableDatagrams: true},
}
defer d.Close()
url := fmt.Sprintf("https://localhost:%d/webtransport", addr.Port)
Expand Down

0 comments on commit 0da5b74

Please sign in to comment.