* quic-go upgrade: replaced Session/EarlySession with Connection/EarlyConnection

* quic-go upgrade: added context to RoundTripper.Dial

* quic-go upgrade: made corresponding changes to tutorial

* quic-go upgrade: changed sess variable instances to qconn

* quic-go upgrade: made corresponding changes to tutorial

* cleanup: remove unnecessary comments

Those comments made sense in terms of illustrating the changes
but they're going to be less useful once we merge.

* fix(go.mod): apparently we needed `go1.18.1 mod tidy`

VSCode just warned me about this. It seems fine to apply this
change as part of the pull request at hand.

* cleanup(netxlite): http3dialer can be removed

We used to use http3dialer to glue a QUIC dialer, which had a
context as its first argument, to the Dial function used by the
HTTP3 transport, which did not have a context as its first
argument.

Now that HTTP3 transport has a Dial function taking a context as
its first argument, we don't need http3dialer
anymore, since we can use the QUIC dialer directly.

Cc: @DecFox

* Revert "cleanup(netxlite): http3dialer can be removed"

This reverts commit c62244c620cee5fadcc2ca89d8228c8db0b96add
to investigate the build failure mentioned at
https://github.com/ooni/probe-cli/pull/715#issuecomment-1119450484

* chore(netx): show that test was already broken

We didn't see the breakage before because we were not using
the created transport, but the issue of using a nil dialer was
already present before, we just didn't see it.

Now we understand why removing the http3transport in
c62244c620cee5fadcc2ca89d8228c8db0b96add did cause the
breakage mentioned at
https://github.com/ooni/probe-cli/pull/715#issuecomment-1119450484

* fix(netx): convert broken integration test to working unit test

There's no point in using the network here. Add a fake dialer that
breaks and ensure we're getting the expected error.

We've now improved upon the original test because the original test was
not doing anything while now we're testing whether we get back a QUIC
dialer that _can be used_.

After this commit, I can then readd the cleanup commit
c62244c620cee5fadcc2ca89d8228c8db0b96add and it won't be
broken anymore (at least, this is what I expected to happen).

* Revert "Revert "cleanup(netxlite): http3dialer can be removed""

This reverts commit 0e254bfc6ba3bfd65365ce3d8de2c8ec51b925ff
because now we should have fixed the broken test.

Co-authored-by: decfox <decfox>
Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
DecFox
2022-05-06 15:54:03 +05:30
committed by GitHub
parent a72cc7151c
commit 5d2afaade4
27 changed files with 285 additions and 294 deletions
+1 -17
View File
@@ -1,30 +1,14 @@
package netxlite
import (
"context"
"crypto/tls"
"io"
"net/http"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/ooni/probe-cli/v3/internal/model"
)
// http3Dialer adapts a QUICContextDialer to work with
// an http3.RoundTripper. This is necessary because the
// http3.RoundTripper does not support DialContext.
type http3Dialer struct {
model.QUICDialer
}
// dial is like QUICContextDialer.DialContext but without context.
func (d *http3Dialer) dial(network, address string, tlsConfig *tls.Config,
quicConfig *quic.Config) (quic.EarlySession, error) {
return d.QUICDialer.DialContext(
context.Background(), network, address, tlsConfig, quicConfig)
}
// http3RoundTripper is the abstract type of quic-go/http3.RoundTripper.
type http3RoundTripper interface {
http.RoundTripper
@@ -63,7 +47,7 @@ func NewHTTP3Transport(
return &httpTransportLogger{
HTTPTransport: &http3Transport{
child: &http3.RoundTripper{
Dial: (&http3Dialer{dialer}).dial,
Dial: dialer.DialContext,
// The following (1) reduces the number of headers that Go will
// automatically send for us and (2) ensures that we always receive
// back the true headers, such as Content-Length. This change is
-22
View File
@@ -1,39 +1,17 @@
package netxlite
import (
"context"
"crypto/tls"
"errors"
"net/http"
"testing"
"github.com/apex/log"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
nlmocks "github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
)
func TestHTTP3Dialer(t *testing.T) {
t.Run("Dial", func(t *testing.T) {
expected := errors.New("mocked error")
d := &http3Dialer{
QUICDialer: &mocks.QUICDialer{
MockDialContext: func(ctx context.Context, network, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
return nil, expected
},
},
}
sess, err := d.dial("", "", &tls.Config{}, &quic.Config{})
if !errors.Is(err, expected) {
t.Fatal("unexpected err", err)
}
if sess != nil {
t.Fatal("unexpected resp")
}
})
}
func TestHTTP3Transport(t *testing.T) {
t.Run("CloseIdleConnections", func(t *testing.T) {
var (
+2 -2
View File
@@ -12,11 +12,11 @@ import (
// DEPRECATED: please use QUICDialer.
type QUICContextDialer struct {
MockDialContext func(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error)
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error)
}
// DialContext calls MockDialContext.
func (qcd *QUICContextDialer) DialContext(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
return qcd.MockDialContext(ctx, network, address, tlsConfig, quicConfig)
}
+1 -1
View File
@@ -13,7 +13,7 @@ func TestQUICContextDialer(t *testing.T) {
t.Run("DialContext", func(t *testing.T) {
expected := errors.New("mocked error")
qcd := &QUICContextDialer{
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
return nil, expected
},
}
+30 -30
View File
@@ -83,7 +83,7 @@ type quicDialerQUICGo struct {
// mockDialEarlyContext allows to mock quic.DialEarlyContext.
mockDialEarlyContext func(ctx context.Context, pconn net.PacketConn,
remoteAddr net.Addr, host string, tlsConfig *tls.Config,
quicConfig *quic.Config) (quic.EarlySession, error)
quicConfig *quic.Config) (quic.EarlyConnection, error)
}
var _ model.QUICDialer = &quicDialerQUICGo{}
@@ -101,7 +101,7 @@ var errInvalidIP = errors.New("netxlite: invalid IP")
// then we configure, respectively, "h3" and "dq".
func (d *quicDialerQUICGo) DialContext(ctx context.Context, network string,
address string, tlsConfig *tls.Config, quicConfig *quic.Config) (
quic.EarlySession, error) {
quic.EarlyConnection, error) {
onlyhost, onlyport, err := net.SplitHostPort(address)
if err != nil {
return nil, err
@@ -120,18 +120,18 @@ func (d *quicDialerQUICGo) DialContext(ctx context.Context, network string,
}
udpAddr := &net.UDPAddr{IP: ip, Port: port, Zone: ""}
tlsConfig = d.maybeApplyTLSDefaults(tlsConfig, port)
sess, err := d.dialEarlyContext(
qconn, err := d.dialEarlyContext(
ctx, pconn, udpAddr, address, tlsConfig, quicConfig)
if err != nil {
pconn.Close() // we own it on failure
return nil, err
}
return &quicSessionOwnsConn{EarlySession: sess, conn: pconn}, nil
return &quicConnectionOwnsConn{EarlyConnection: qconn, conn: pconn}, nil
}
func (d *quicDialerQUICGo) dialEarlyContext(ctx context.Context,
pconn net.PacketConn, remoteAddr net.Addr, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
if d.mockDialEarlyContext != nil {
return d.mockDialEarlyContext(
ctx, pconn, remoteAddr, address, tlsConfig, quicConfig)
@@ -164,20 +164,20 @@ func (d *quicDialerQUICGo) CloseIdleConnections() {
// nothing to do
}
// quicSessionOwnsConn ensures that we close the UDPLikeConn.
type quicSessionOwnsConn struct {
// EarlySession is the embedded early session
quic.EarlySession
// quicConnectionOwnsConn ensures that we close the UDPLikeConn.
type quicConnectionOwnsConn struct {
// EarlyConnection is the embedded early connection
quic.EarlyConnection
// conn is the connection we own
conn model.UDPLikeConn
}
// CloseWithError implements quic.EarlySession.CloseWithError.
func (sess *quicSessionOwnsConn) CloseWithError(
// CloseWithError implements quic.EarlyConnection.CloseWithError.
func (qconn *quicConnectionOwnsConn) CloseWithError(
code quic.ApplicationErrorCode, reason string) error {
err := sess.EarlySession.CloseWithError(code, reason)
sess.conn.Close()
err := qconn.EarlyConnection.CloseWithError(code, reason)
qconn.conn.Close()
return err
}
@@ -200,7 +200,7 @@ var _ model.QUICDialer = &quicDialerResolver{}
// contained inside of the `address` endpoint.
func (d *quicDialerResolver) DialContext(
ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
onlyhost, onlyport, err := net.SplitHostPort(address)
if err != nil {
return nil, err
@@ -217,10 +217,10 @@ func (d *quicDialerResolver) DialContext(
var errorslist []error
for _, addr := range addrs {
target := net.JoinHostPort(addr, onlyport)
sess, err := d.Dialer.DialContext(
qconn, err := d.Dialer.DialContext(
ctx, network, target, tlsConfig, quicConfig)
if err == nil {
return sess, nil
return qconn, nil
}
errorslist = append(errorslist, err)
}
@@ -272,16 +272,16 @@ var _ model.QUICDialer = &quicDialerLogger{}
// DialContext implements QUICContextDialer.DialContext.
func (d *quicDialerLogger) DialContext(
ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
d.Logger.Debugf("quic_dial%s %s/%s...", d.operationSuffix, address, network)
sess, err := d.Dialer.DialContext(ctx, network, address, tlsConfig, quicConfig)
qconn, err := d.Dialer.DialContext(ctx, network, address, tlsConfig, quicConfig)
if err != nil {
d.Logger.Debugf("quic_dial%s %s/%s... %s", d.operationSuffix,
address, network, err)
return nil, err
}
d.Logger.Debugf("quic_dial%s %s/%s... ok", d.operationSuffix, address, network)
return sess, nil
return qconn, nil
}
// CloseIdleConnections implements QUICDialer.CloseIdleConnections.
@@ -290,14 +290,14 @@ func (d *quicDialerLogger) CloseIdleConnections() {
}
// NewSingleUseQUICDialer is like NewSingleUseDialer but for QUIC.
func NewSingleUseQUICDialer(sess quic.EarlySession) model.QUICDialer {
return &quicDialerSingleUse{sess: sess}
func NewSingleUseQUICDialer(qconn quic.EarlyConnection) model.QUICDialer {
return &quicDialerSingleUse{qconn: qconn}
}
// quicDialerSingleUse is the QUICDialer returned by NewSingleQUICDialer.
type quicDialerSingleUse struct {
sync.Mutex
sess quic.EarlySession
qconn quic.EarlyConnection
}
var _ model.QUICDialer = &quicDialerSingleUse{}
@@ -305,15 +305,15 @@ var _ model.QUICDialer = &quicDialerSingleUse{}
// DialContext implements QUICDialer.DialContext.
func (s *quicDialerSingleUse) DialContext(
ctx context.Context, network, addr string, tlsCfg *tls.Config,
cfg *quic.Config) (quic.EarlySession, error) {
var sess quic.EarlySession
cfg *quic.Config) (quic.EarlyConnection, error) {
var qconn quic.EarlyConnection
defer s.Unlock()
s.Lock()
if s.sess == nil {
if s.qconn == nil {
return nil, ErrNoConnReuse
}
sess, s.sess = s.sess, nil
return sess, nil
qconn, s.qconn = s.qconn, nil
return qconn, nil
}
// CloseIdleConnections closes idle connections.
@@ -381,11 +381,11 @@ type quicDialerErrWrapper struct {
// DialContext implements ContextDialer.DialContext
func (d *quicDialerErrWrapper) DialContext(
ctx context.Context, network string, host string,
tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlySession, error) {
sess, err := d.QUICDialer.DialContext(ctx, network, host, tlsCfg, cfg)
tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlyConnection, error) {
qconn, err := d.QUICDialer.DialContext(ctx, network, host, tlsCfg, cfg)
if err != nil {
return nil, NewErrWrapper(
classifyQUICHandshakeError, QUICHandshakeOperation, err)
}
return sess, nil
return qconn, nil
}
+61 -61
View File
@@ -55,13 +55,13 @@ func TestQUICDialerQUICGo(t *testing.T) {
}
defer systemdialer.CloseIdleConnections() // just to see it running
ctx := context.Background()
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "a.b.c.d", tlsConfig, &quic.Config{})
if err == nil || !strings.HasSuffix(err.Error(), "missing port in address") {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil sess here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
})
@@ -73,13 +73,13 @@ func TestQUICDialerQUICGo(t *testing.T) {
QUICListener: &quicListenerStdlib{},
}
ctx := context.Background()
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "8.8.4.4:xyz", tlsConfig, &quic.Config{})
if err == nil || !strings.HasSuffix(err.Error(), "invalid syntax") {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil sess here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
})
@@ -91,13 +91,13 @@ func TestQUICDialerQUICGo(t *testing.T) {
QUICListener: &quicListenerStdlib{},
}
ctx := context.Background()
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "a.b.c.d:0", tlsConfig, &quic.Config{})
if !errors.Is(err, errInvalidIP) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil sess here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
})
@@ -114,13 +114,13 @@ func TestQUICDialerQUICGo(t *testing.T) {
},
}
ctx := context.Background()
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "8.8.8.8:443", tlsConfig, &quic.Config{})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil sess here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
})
@@ -133,13 +133,13 @@ func TestQUICDialerQUICGo(t *testing.T) {
}
ctx, cancel := context.WithCancel(context.Background())
cancel() // fail immediately
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "8.8.8.8:443", tlsConfig, &quic.Config{})
if !errors.Is(err, context.Canceled) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
log.Fatal("expected nil session here")
if qconn != nil {
log.Fatal("expected nil connection here")
}
})
@@ -153,19 +153,19 @@ func TestQUICDialerQUICGo(t *testing.T) {
QUICListener: &quicListenerStdlib{},
mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn,
remoteAddr net.Addr, host string, tlsConfig *tls.Config,
quicConfig *quic.Config) (quic.EarlySession, error) {
quicConfig *quic.Config) (quic.EarlyConnection, error) {
gotTLSConfig = tlsConfig
return nil, expected
},
}
ctx := context.Background()
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "8.8.8.8:443", tlsConfig, &quic.Config{})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil session here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
if tlsConfig.RootCAs != nil {
t.Fatal("tlsConfig.RootCAs should not have been changed")
@@ -194,19 +194,19 @@ func TestQUICDialerQUICGo(t *testing.T) {
QUICListener: &quicListenerStdlib{},
mockDialEarlyContext: func(ctx context.Context, pconn net.PacketConn,
remoteAddr net.Addr, host string, tlsConfig *tls.Config,
quicConfig *quic.Config) (quic.EarlySession, error) {
quicConfig *quic.Config) (quic.EarlyConnection, error) {
gotTLSConfig = tlsConfig
return nil, expected
},
}
ctx := context.Background()
sess, err := systemdialer.DialContext(
qconn, err := systemdialer.DialContext(
ctx, "udp", "8.8.8.8:8853", tlsConfig, &quic.Config{})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil session here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
if tlsConfig.RootCAs != nil {
t.Fatal("tlsConfig.RootCAs should not have been changed")
@@ -257,14 +257,14 @@ func TestQUICDialerResolver(t *testing.T) {
dialer := &quicDialerResolver{
Resolver: NewResolverStdlib(log.Log),
Dialer: &quicDialerQUICGo{}}
sess, err := dialer.DialContext(
qconn, err := dialer.DialContext(
context.Background(), "udp", "www.google.com",
tlsConfig, &quic.Config{})
if err == nil || !strings.HasSuffix(err.Error(), "missing port in address") {
t.Fatal("not the error we expected")
}
if sess != nil {
t.Fatal("expected a nil sess here")
if qconn != nil {
t.Fatal("expected a nil connection here")
}
})
@@ -276,14 +276,14 @@ func TestQUICDialerResolver(t *testing.T) {
return nil, expected
},
}}
sess, err := dialer.DialContext(
qconn, err := dialer.DialContext(
context.Background(), "udp", "dns.google.com:853",
tlsConfig, &quic.Config{})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected")
}
if sess != nil {
t.Fatal("expected nil sess")
if qconn != nil {
t.Fatal("expected nil connection")
}
})
@@ -296,7 +296,7 @@ func TestQUICDialerResolver(t *testing.T) {
Dialer: &quicDialerQUICGo{
QUICListener: &quicListenerStdlib{},
}}
sess, err := dialer.DialContext(
qconn, err := dialer.DialContext(
context.Background(), "udp", "8.8.4.4:x",
tlsConf, &quic.Config{})
if err == nil {
@@ -305,8 +305,8 @@ func TestQUICDialerResolver(t *testing.T) {
if !strings.HasSuffix(err.Error(), "invalid syntax") {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil sess")
if qconn != nil {
t.Fatal("expected nil connection")
}
})
@@ -318,19 +318,19 @@ func TestQUICDialerResolver(t *testing.T) {
Resolver: NewResolverStdlib(log.Log),
Dialer: &mocks.QUICDialer{
MockDialContext: func(ctx context.Context, network, address string,
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
gotTLSConfig = tlsConfig
return nil, expected
},
}}
sess, err := dialer.DialContext(
qconn, err := dialer.DialContext(
context.Background(), "udp", "8.8.4.4:443",
tlsConfig, &quic.Config{})
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil session here")
if qconn != nil {
t.Fatal("expected nil connection here")
}
if tlsConfig.ServerName != "" {
t.Fatal("should not have changed tlsConfig.ServerName")
@@ -387,8 +387,8 @@ func TestQUICLoggerDialer(t *testing.T) {
Dialer: &mocks.QUICDialer{
MockDialContext: func(ctx context.Context, network string,
address string, tlsConfig *tls.Config,
quicConfig *quic.Config) (quic.EarlySession, error) {
return &mocks.QUICEarlySession{
quicConfig *quic.Config) (quic.EarlyConnection, error) {
return &mocks.QUICEarlyConnection{
MockCloseWithError: func(
code quic.ApplicationErrorCode, reason string) error {
return nil
@@ -401,11 +401,11 @@ func TestQUICLoggerDialer(t *testing.T) {
ctx := context.Background()
tlsConfig := &tls.Config{}
quicConfig := &quic.Config{}
sess, err := d.DialContext(ctx, "udp", "8.8.8.8:443", tlsConfig, quicConfig)
qconn, err := d.DialContext(ctx, "udp", "8.8.8.8:443", tlsConfig, quicConfig)
if err != nil {
t.Fatal(err)
}
if err := sess.CloseWithError(0, ""); err != nil {
if err := qconn.CloseWithError(0, ""); err != nil {
t.Fatal(err)
}
if called != 2 {
@@ -425,7 +425,7 @@ func TestQUICLoggerDialer(t *testing.T) {
Dialer: &mocks.QUICDialer{
MockDialContext: func(ctx context.Context, network string,
address string, tlsConfig *tls.Config,
quicConfig *quic.Config) (quic.EarlySession, error) {
quicConfig *quic.Config) (quic.EarlyConnection, error) {
return nil, expected
},
},
@@ -434,12 +434,12 @@ func TestQUICLoggerDialer(t *testing.T) {
ctx := context.Background()
tlsConfig := &tls.Config{}
quicConfig := &quic.Config{}
sess, err := d.DialContext(ctx, "udp", "8.8.8.8:443", tlsConfig, quicConfig)
qconn, err := d.DialContext(ctx, "udp", "8.8.8.8:443", tlsConfig, quicConfig)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if sess != nil {
t.Fatal("expected nil session")
if qconn != nil {
t.Fatal("expected nil connection")
}
if called != 2 {
t.Fatal("invalid number of calls")
@@ -449,24 +449,24 @@ func TestQUICLoggerDialer(t *testing.T) {
}
func TestNewSingleUseQUICDialer(t *testing.T) {
sess := &mocks.QUICEarlySession{}
qd := NewSingleUseQUICDialer(sess)
qconn := &mocks.QUICEarlyConnection{}
qd := NewSingleUseQUICDialer(qconn)
defer qd.CloseIdleConnections()
outsess, err := qd.DialContext(
outconn, err := qd.DialContext(
context.Background(), "", "", &tls.Config{}, &quic.Config{})
if err != nil {
t.Fatal(err)
}
if sess != outsess {
t.Fatal("invalid outsess")
if qconn != outconn {
t.Fatal("invalid outconn")
}
for i := 0; i < 4; i++ {
outsess, err = qd.DialContext(
outconn, err = qd.DialContext(
context.Background(), "", "", &tls.Config{}, &quic.Config{})
if !errors.Is(err, ErrNoConnReuse) {
t.Fatal("not the error we expected", err)
}
if outsess != nil {
if outconn != nil {
t.Fatal("expected nil outconn here")
}
}
@@ -649,21 +649,21 @@ func TestQUICDialerErrWrapper(t *testing.T) {
t.Run("DialContext", func(t *testing.T) {
t.Run("on success", func(t *testing.T) {
expectedSess := &mocks.QUICEarlySession{}
expectedConn := &mocks.QUICEarlyConnection{}
d := &quicDialerErrWrapper{
QUICDialer: &mocks.QUICDialer{
MockDialContext: func(ctx context.Context, network, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
return expectedSess, nil
MockDialContext: func(ctx context.Context, network, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
return expectedConn, nil
},
},
}
ctx := context.Background()
sess, err := d.DialContext(ctx, "", "", &tls.Config{}, &quic.Config{})
qconn, err := d.DialContext(ctx, "", "", &tls.Config{}, &quic.Config{})
if err != nil {
t.Fatal(err)
}
if sess != expectedSess {
t.Fatal("unexpected sess")
if qconn != expectedConn {
t.Fatal("unexpected connection")
}
})
@@ -671,18 +671,18 @@ func TestQUICDialerErrWrapper(t *testing.T) {
expectedErr := io.EOF
d := &quicDialerErrWrapper{
QUICDialer: &mocks.QUICDialer{
MockDialContext: func(ctx context.Context, network, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
MockDialContext: func(ctx context.Context, network, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlyConnection, error) {
return nil, expectedErr
},
},
}
ctx := context.Background()
sess, err := d.DialContext(ctx, "", "", &tls.Config{}, &quic.Config{})
qconn, err := d.DialContext(ctx, "", "", &tls.Config{}, &quic.Config{})
if err == nil || err.Error() != FailureEOFError {
t.Fatal("unexpected err", err)
}
if sess != nil {
t.Fatal("unexpected sess")
if qconn != nil {
t.Fatal("unexpected connection")
}
})
})