From 5b27df1a37e0a279222e3f8c8dcffc0e5ac839f7 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Fri, 8 Jul 2022 12:29:08 +0200 Subject: [PATCH] measurexlite: fix flaky tls_test.go (#839) Bug reported by @DecFox and subsequently observed in several CI builds. No need to create an issue. --- internal/measurexlite/tls_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/measurexlite/tls_test.go b/internal/measurexlite/tls_test.go index cd0f462..de51f14 100644 --- a/internal/measurexlite/tls_test.go +++ b/internal/measurexlite/tls_test.go @@ -76,8 +76,7 @@ func TestNewTLSHandshakerStdlib(t *testing.T) { trace := NewTrace(0, zeroTime) trace.TimeNowFn = td.Now // deterministic timing thx := trace.NewTLSHandshakerStdlib(model.DiscardLogger) - ctx, cancel := context.WithCancel(context.Background()) - cancel() // we cancel immediately so connect is ~instantaneous + ctx := context.Background() tcpConn := &mocks.Conn{ MockSetDeadline: func(t time.Time) error { return nil @@ -104,7 +103,7 @@ func TestNewTLSHandshakerStdlib(t *testing.T) { ServerName: "dns.cloudflare.com", } conn, state, err := thx.Handshake(ctx, tcpConn, tlsConfig) - if err == nil || err.Error() != netxlite.FailureInterrupted { + if !errors.Is(err, mockedErr) { t.Fatal("unexpected err", err) } if !reflect.ValueOf(state).IsZero() { @@ -119,7 +118,7 @@ func TestNewTLSHandshakerStdlib(t *testing.T) { if len(events) != 1 { t.Fatal("expected to see single TLSHandshake event") } - expectedFailure := netxlite.FailureInterrupted + expectedFailure := "unknown_failure: mocked" expect := &model.ArchivalTLSOrQUICHandshakeResult{ Address: "1.1.1.1:443", CipherSuite: "", @@ -185,8 +184,7 @@ func TestNewTLSHandshakerStdlib(t *testing.T) { trace.NetworkEvent = make(chan *model.ArchivalNetworkEvent) // no buffer trace.TLSHandshake = make(chan *model.ArchivalTLSOrQUICHandshakeResult) // no buffer thx := trace.NewTLSHandshakerStdlib(model.DiscardLogger) - ctx, cancel := context.WithCancel(context.Background()) - cancel() // we cancel immediately so connect is ~instantaneous + ctx := context.Background() tcpConn := &mocks.Conn{ MockSetDeadline: func(t time.Time) error { return nil @@ -213,7 +211,7 @@ func TestNewTLSHandshakerStdlib(t *testing.T) { ServerName: "dns.cloudflare.com", } conn, state, err := thx.Handshake(ctx, tcpConn, tlsConfig) - if err == nil || err.Error() != netxlite.FailureInterrupted { + if !errors.Is(err, mockedErr) { t.Fatal("unexpected err", err) } if !reflect.ValueOf(state).IsZero() {