Skip to content

Commit

Permalink
Merge pull request #9593 from planetscale/ds-net-listen
Browse files Browse the repository at this point in the history
tests: change the way we call net.Listen to avoid annoying popups on macOS
  • Loading branch information
deepthi authored Jan 30, 2022
2 parents 9e6f70d + 55709c3 commit a033d76
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go/netutil/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func createSocketPair(t *testing.T) (net.Listener, net.Conn, net.Conn) {
// Create a listener.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Listen failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/test/fuzzing/tablet_manager_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func initTesting() {
testing.Init()
}

func FuzzTabletManager_ExecuteFetchAsDba(data []byte) int {
func FuzzTabletManagerExecuteFetchAsDba(data []byte) int {
fuzzInitter.Do(initTesting)
t := &testing.T{}
ctx := context.Background()
Expand Down
6 changes: 3 additions & 3 deletions go/test/fuzzing/vtctl_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ func Fuzz(data []byte) int {
// Index of command in getCommandType():
commandIndex := int(commandPart[command]) % 68
vtCommand := getCommandType(commandIndex)
command_slice := []string{vtCommand}
commandSlice := []string{vtCommand}
args := strings.Split(string(restOfArray[from:to]), " ")

// Add params to the command
for i := range args {
command_slice = append(command_slice, args[i])
commandSlice = append(commandSlice, args[i])
}

_ = vtctl.RunCommand(ctx, wrangler.New(logger, topo, tmc), command_slice)
_ = vtctl.RunCommand(ctx, wrangler.New(logger, topo, tmc), commandSlice)
command++
}

Expand Down
2 changes: 1 addition & 1 deletion go/test/fuzzing/vttablet_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ func FuzzGRPCTMServer(data []byte) int {
t := &testing.T{}

// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/binlog/grpcbinlogplayer/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// implementation, and runs the test suite against the setup.
func TestGRPCBinlogStreamer(t *testing.T) {
// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions go/vt/grpcoptionaltls/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestOptionalTLS(t *testing.T) {
t.Fatalf("failed to create credentials %v", err)
}

lis, err := net.Listen("tcp", "")
lis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("failed to listen %v", err)
}
Expand Down Expand Up @@ -114,12 +114,12 @@ func TestOptionalTLS(t *testing.T) {
}

t.Run("Plain2TLS", func(t *testing.T) {
for i := 0; i < 5; i += 1 {
for i := 0; i < 5; i++ {
testFunc(t, grpc.WithInsecure())
}
})
t.Run("TLS2TLS", func(t *testing.T) {
for i := 0; i < 5; i += 1 {
for i := 0; i < 5; i++ {
testFunc(t, grpc.WithTransportCredentials(tc.client))
}
})
Expand Down
2 changes: 1 addition & 1 deletion go/vt/servenv/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestURLPrefix(t *testing.T) {

func TestHandleFunc(t *testing.T) {
// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestThrottlerServerPanics(t *testing.T) {

func startGRPCServer(t *testing.T, m throttler.Manager) int {
// Listen on a random port.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/tlstest/tlstest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func testClientServer(t *testing.T, combineCerts bool) {
}

// Create a TLS server listener.
listener, err := tls.Listen("tcp", ":0", serverConfig)
listener, err := tls.Listen("tcp", "127.0.0.1:0", serverConfig)
if err != nil {
t.Fatalf("Listen failed: %v", err)
}
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestNumberOfCertsWithCombining(t *testing.T) {

func assertTLSHandshakeFails(t *testing.T, serverConfig, clientConfig *tls.Config) {
// Create a TLS server listener.
listener, err := tls.Listen("tcp", ":0", serverConfig)
listener, err := tls.Listen("tcp", "127.0.0.1:0", serverConfig)
if err != nil {
t.Fatalf("Listen failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vitessdriver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestMain(m *testing.M) {
service := CreateFakeServer()

// listen on a random port.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(fmt.Sprintf("Cannot listen: %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtadmin/vtctldclient/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type fakeVtctld struct {
}

func TestDial(t *testing.T) {
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

defer listener.Close()
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtctl/grpcvtctlclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestVtctlServer(t *testing.T) {
ts := vtctlclienttest.CreateTopoServer(t)

// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand All @@ -66,7 +66,7 @@ func TestVtctlAuthClient(t *testing.T) {
ts := vtctlclienttest.CreateTopoServer(t)

// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/grpc_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGRPCDiscovery(t *testing.T) {
service, ts, cell := CreateFakeServers(t)

// Tablet: listen on a random port.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/grpcvtgateconn/conn_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestGRPCVTGateConn(t *testing.T) {
service := CreateFakeServer(t)

// listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestGRPCVTGateConnAuth(t *testing.T) {
service := CreateFakeServer(t)

// listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Fuzz(data []byte) int {
service := CreateFakeServer(t)

// listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
fmt.Println("Cannot listen")
return -1
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/endtoend/framework/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func StartCustomServer(connParams, connAppDebugParams mysql.ConnParams, dbName s
}

// Start http service.
ln, err := net.Listen("tcp", ":0")
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return vterrors.Wrap(err, "could not start listener")
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/grpctabletconn/conn_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func BenchmarkGRPCTabletConn(b *testing.B) {
}

// listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
b.Fatalf("Cannot listen: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/grpctabletconn/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGRPCTabletConn(t *testing.T) {
service := tabletconntest.CreateFakeServer(t)

// listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestGRPCTabletAuthConn(t *testing.T) {
service := tabletconntest.CreateFakeServer(t)

// listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/grpctmserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// implementation, and runs the test suite against the setup.
func TestGRPCTMServer(t *testing.T) {
// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/worker/grpcvtworkerclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestVtworkerServer(t *testing.T) {
wi := vtworkerclienttest.CreateWorkerInstance(t)

// Listen on a random port.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand All @@ -64,7 +64,7 @@ func TestVtworkerServerAuth(t *testing.T) {
wi := vtworkerclienttest.CreateWorkerInstance(t)

// Listen on a random port.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/workflow/long_polling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestLongPolling(t *testing.T) {

// Register the manager to a web handler, start a web server.
m.HandleHTTPLongPolling("/workflow")
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/workflow/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestWebSocket(t *testing.T) {

// Register the manager to a web handler, start a web server.
m.HandleHTTPWebSocket("/workflow")
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/testlib/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
// "Resharding Throttler" group.
func TestVtctlThrottlerCommands(t *testing.T) {
// Run a throttler server using the default process throttle manager.
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/testlib/vtctl_pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewVtctlPipe(t *testing.T, ts *topo.Server) *VtctlPipe {
})

// Listen on a random port
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Cannot listen: %v", err)
}
Expand Down

0 comments on commit a033d76

Please sign in to comment.