From 55709c3bca145bc6a541a91f004e7c2f3a9aa8c5 Mon Sep 17 00:00:00 2001 From: deepthi Date: Fri, 28 Jan 2022 13:45:01 -0800 Subject: [PATCH] tests: change the way we call net.Listen to avoid annoying popups on macOS Signed-off-by: deepthi --- go/netutil/conn_test.go | 2 +- go/test/fuzzing/tablet_manager_fuzzer.go | 2 +- go/test/fuzzing/vtctl_fuzzer.go | 6 +++--- go/test/fuzzing/vttablet_fuzzer.go | 2 +- go/vt/binlog/grpcbinlogplayer/player_test.go | 2 +- go/vt/grpcoptionaltls/server_test.go | 6 +++--- go/vt/servenv/exporter_test.go | 2 +- .../grpcthrottlerclient/grpcthrottlerclient_test.go | 2 +- go/vt/tlstest/tlstest_test.go | 4 ++-- go/vt/vitessdriver/driver_test.go | 2 +- go/vt/vtadmin/vtctldclient/proxy_test.go | 2 +- go/vt/vtctl/grpcvtctlclient/client_test.go | 4 ++-- go/vt/vtgate/grpc_discovery_test.go | 2 +- go/vt/vtgate/grpcvtgateconn/conn_rpc_test.go | 4 ++-- go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go | 2 +- go/vt/vttablet/endtoend/framework/server.go | 2 +- go/vt/vttablet/grpctabletconn/conn_benchmark_test.go | 2 +- go/vt/vttablet/grpctabletconn/conn_test.go | 4 ++-- go/vt/vttablet/grpctmserver/server_test.go | 2 +- go/vt/worker/grpcvtworkerclient/client_test.go | 4 ++-- go/vt/workflow/long_polling_test.go | 2 +- go/vt/workflow/websocket_test.go | 2 +- go/vt/wrangler/testlib/throttler_test.go | 2 +- go/vt/wrangler/testlib/vtctl_pipe.go | 2 +- 24 files changed, 33 insertions(+), 33 deletions(-) diff --git a/go/netutil/conn_test.go b/go/netutil/conn_test.go index 083df3ba81e..78776035856 100644 --- a/go/netutil/conn_test.go +++ b/go/netutil/conn_test.go @@ -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) } diff --git a/go/test/fuzzing/tablet_manager_fuzzer.go b/go/test/fuzzing/tablet_manager_fuzzer.go index ab860525917..be89da56ae0 100644 --- a/go/test/fuzzing/tablet_manager_fuzzer.go +++ b/go/test/fuzzing/tablet_manager_fuzzer.go @@ -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() diff --git a/go/test/fuzzing/vtctl_fuzzer.go b/go/test/fuzzing/vtctl_fuzzer.go index 308c3c46579..59da236f7fe 100644 --- a/go/test/fuzzing/vtctl_fuzzer.go +++ b/go/test/fuzzing/vtctl_fuzzer.go @@ -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++ } diff --git a/go/test/fuzzing/vttablet_fuzzer.go b/go/test/fuzzing/vttablet_fuzzer.go index bd94bc0084d..41bf0018065 100644 --- a/go/test/fuzzing/vttablet_fuzzer.go +++ b/go/test/fuzzing/vttablet_fuzzer.go @@ -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 } diff --git a/go/vt/binlog/grpcbinlogplayer/player_test.go b/go/vt/binlog/grpcbinlogplayer/player_test.go index b9d29e97301..bde54cd2113 100644 --- a/go/vt/binlog/grpcbinlogplayer/player_test.go +++ b/go/vt/binlog/grpcbinlogplayer/player_test.go @@ -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) } diff --git a/go/vt/grpcoptionaltls/server_test.go b/go/vt/grpcoptionaltls/server_test.go index 269f7decf4e..e46b1ee09e2 100755 --- a/go/vt/grpcoptionaltls/server_test.go +++ b/go/vt/grpcoptionaltls/server_test.go @@ -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) } @@ -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)) } }) diff --git a/go/vt/servenv/exporter_test.go b/go/vt/servenv/exporter_test.go index 9bfbabeb250..4a9edf4da6e 100644 --- a/go/vt/servenv/exporter_test.go +++ b/go/vt/servenv/exporter_test.go @@ -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) } diff --git a/go/vt/throttler/grpcthrottlerclient/grpcthrottlerclient_test.go b/go/vt/throttler/grpcthrottlerclient/grpcthrottlerclient_test.go index 7b7e5860dec..d3ae3c40a33 100644 --- a/go/vt/throttler/grpcthrottlerclient/grpcthrottlerclient_test.go +++ b/go/vt/throttler/grpcthrottlerclient/grpcthrottlerclient_test.go @@ -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) } diff --git a/go/vt/tlstest/tlstest_test.go b/go/vt/tlstest/tlstest_test.go index 34d57ed0a28..26bc192214c 100644 --- a/go/vt/tlstest/tlstest_test.go +++ b/go/vt/tlstest/tlstest_test.go @@ -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) } @@ -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) } diff --git a/go/vt/vitessdriver/driver_test.go b/go/vt/vitessdriver/driver_test.go index 6af7a534de8..5438aa0c75d 100644 --- a/go/vt/vitessdriver/driver_test.go +++ b/go/vt/vitessdriver/driver_test.go @@ -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)) } diff --git a/go/vt/vtadmin/vtctldclient/proxy_test.go b/go/vt/vtadmin/vtctldclient/proxy_test.go index f92b443ecf1..d256a030a54 100644 --- a/go/vt/vtadmin/vtctldclient/proxy_test.go +++ b/go/vt/vtadmin/vtctldclient/proxy_test.go @@ -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() diff --git a/go/vt/vtctl/grpcvtctlclient/client_test.go b/go/vt/vtctl/grpcvtctlclient/client_test.go index 8698a500202..7b3ce93ddd3 100644 --- a/go/vt/vtctl/grpcvtctlclient/client_test.go +++ b/go/vt/vtctl/grpcvtctlclient/client_test.go @@ -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) } @@ -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) } diff --git a/go/vt/vtgate/grpc_discovery_test.go b/go/vt/vtgate/grpc_discovery_test.go index 13cd7e1644e..4aaabe148dd 100644 --- a/go/vt/vtgate/grpc_discovery_test.go +++ b/go/vt/vtgate/grpc_discovery_test.go @@ -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) } diff --git a/go/vt/vtgate/grpcvtgateconn/conn_rpc_test.go b/go/vt/vtgate/grpcvtgateconn/conn_rpc_test.go index c88784621c9..28f9573634e 100644 --- a/go/vt/vtgate/grpcvtgateconn/conn_rpc_test.go +++ b/go/vt/vtgate/grpcvtgateconn/conn_rpc_test.go @@ -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) } @@ -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) } diff --git a/go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go b/go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go index d07e5dae214..e01c14eb8c4 100644 --- a/go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go +++ b/go/vt/vtgate/grpcvtgateconn/fuzz_flaky_test.go @@ -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 diff --git a/go/vt/vttablet/endtoend/framework/server.go b/go/vt/vttablet/endtoend/framework/server.go index a82ea58865f..a897f605d84 100644 --- a/go/vt/vttablet/endtoend/framework/server.go +++ b/go/vt/vttablet/endtoend/framework/server.go @@ -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") } diff --git a/go/vt/vttablet/grpctabletconn/conn_benchmark_test.go b/go/vt/vttablet/grpctabletconn/conn_benchmark_test.go index afec3fc6ced..72b142c73e1 100644 --- a/go/vt/vttablet/grpctabletconn/conn_benchmark_test.go +++ b/go/vt/vttablet/grpctabletconn/conn_benchmark_test.go @@ -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) } diff --git a/go/vt/vttablet/grpctabletconn/conn_test.go b/go/vt/vttablet/grpctabletconn/conn_test.go index 16776f24d6d..fb182bfe2e4 100644 --- a/go/vt/vttablet/grpctabletconn/conn_test.go +++ b/go/vt/vttablet/grpctabletconn/conn_test.go @@ -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) } @@ -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) } diff --git a/go/vt/vttablet/grpctmserver/server_test.go b/go/vt/vttablet/grpctmserver/server_test.go index e8be1088604..ed0f5a1597f 100644 --- a/go/vt/vttablet/grpctmserver/server_test.go +++ b/go/vt/vttablet/grpctmserver/server_test.go @@ -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) } diff --git a/go/vt/worker/grpcvtworkerclient/client_test.go b/go/vt/worker/grpcvtworkerclient/client_test.go index 88382acb9a4..22ba809664d 100644 --- a/go/vt/worker/grpcvtworkerclient/client_test.go +++ b/go/vt/worker/grpcvtworkerclient/client_test.go @@ -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) } @@ -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) } diff --git a/go/vt/workflow/long_polling_test.go b/go/vt/workflow/long_polling_test.go index 6cfcd8c963f..78314b0376e 100644 --- a/go/vt/workflow/long_polling_test.go +++ b/go/vt/workflow/long_polling_test.go @@ -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) } diff --git a/go/vt/workflow/websocket_test.go b/go/vt/workflow/websocket_test.go index cc4e68b0db7..e47b730e9ad 100644 --- a/go/vt/workflow/websocket_test.go +++ b/go/vt/workflow/websocket_test.go @@ -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) } diff --git a/go/vt/wrangler/testlib/throttler_test.go b/go/vt/wrangler/testlib/throttler_test.go index 0bcc2c11ed2..f5e7ff037a6 100644 --- a/go/vt/wrangler/testlib/throttler_test.go +++ b/go/vt/wrangler/testlib/throttler_test.go @@ -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) } diff --git a/go/vt/wrangler/testlib/vtctl_pipe.go b/go/vt/wrangler/testlib/vtctl_pipe.go index 6adc350dc32..951c5c52734 100644 --- a/go/vt/wrangler/testlib/vtctl_pipe.go +++ b/go/vt/wrangler/testlib/vtctl_pipe.go @@ -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) }