measurexlite: fix flaky tls_test.go (#839)

Bug reported by @DecFox and subsequently observed in several
CI builds. No need to create an issue.
This commit is contained in:
Simone Basso 2022-07-08 12:29:08 +02:00 committed by GitHub
parent 086ae43b15
commit 5b27df1a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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() {