Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/vt/tlstest: fix nilness issues #14812

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions go/vt/tlstest/tlstest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"golang.org/x/sync/errgroup"

"vitess.io/vitess/go/vt/vttls"
)
Expand Down Expand Up @@ -89,21 +90,20 @@ func testClientServer(t *testing.T, combineCerts bool) {
dialer := new(net.Dialer)
dialer.Timeout = 10 * time.Second

wg := sync.WaitGroup{}

//
// Positive case: accept on server side, connect a client, send data.
//
var clientErr error
wg.Add(1)
go func() {
defer wg.Done()
clientConn, clientErr := tls.DialWithDialer(dialer, "tcp", addr, clientConfig)
if clientErr == nil {
_, _ = clientConn.Write([]byte{42})
clientConn.Close()
var clientEG errgroup.Group
clientEG.Go(func() error {
conn, err := tls.DialWithDialer(dialer, "tcp", addr, clientConfig)
if err != nil {
return err
}
}()

_, _ = conn.Write([]byte{42})
_ = conn.Close()
return nil
})

serverConn, err := listener.Accept()
if err != nil {
Expand All @@ -119,10 +119,8 @@ func testClientServer(t *testing.T, combineCerts bool) {
}
serverConn.Close()

wg.Wait()

if clientErr != nil {
t.Fatalf("Dial failed: %v", clientErr)
if err := clientEG.Wait(); err != nil {
t.Fatalf("client dial failed: %v", err)
}

//
Expand All @@ -142,21 +140,23 @@ func testClientServer(t *testing.T, combineCerts bool) {
t.Fatalf("TLSClientConfig failed: %v", err)
}

var serverErr error
wg.Add(1)
go func() {
var serverEG errgroup.Group
serverEG.Go(func() error {
// We expect the Accept to work, but the first read to fail.
defer wg.Done()
serverConn, serverErr := listener.Accept()
conn, err := listener.Accept()
if err != nil {
return err
}

// This will fail.
if serverErr == nil {
result := make([]byte, 1)
if n, err := serverConn.Read(result); err == nil {
fmt.Printf("Was able to read from server: %v\n", n)
}
serverConn.Close()
result := make([]byte, 1)
if n, err := conn.Read(result); err == nil {
return fmt.Errorf("unexpectedly able to read %d bytes from server", n)
}
}()

_ = conn.Close()
return nil
})

// When using TLS 1.2, the Dial will fail.
// With TLS 1.3, the Dial will succeed and the first Read will fail.
Expand All @@ -167,9 +167,9 @@ func testClientServer(t *testing.T, combineCerts bool) {
}
return
}
wg.Wait()
if serverErr != nil {
t.Fatalf("Connection failed: %v", serverErr)

if err := serverEG.Wait(); err != nil {
t.Fatalf("server read failed: %v", err)
}

data := make([]byte, 1)
Expand Down
Loading