diff --git a/pkg/cmd/roachtest/main.go b/pkg/cmd/roachtest/main.go index 82af29f4b728..8694704fc7c3 100644 --- a/pkg/cmd/roachtest/main.go +++ b/pkg/cmd/roachtest/main.go @@ -376,8 +376,15 @@ func runTests(register func(registry.Registry), cfg cliCfg) error { filter := registry.NewTestFilter(cfg.args) clusterType := roachprodCluster + bindTo := "" if local { clusterType = localCluster + + // This will suppress the annoying "Allow incoming network connections" popup from + // OSX when running a roachtest + bindTo = "localhost" + + fmt.Printf("--local specified. Binding http listener to localhost only") if cfg.parallelism != 1 { fmt.Printf("--local specified. Overriding --parallelism to 1.\n") cfg.parallelism = 1 @@ -392,7 +399,7 @@ func runTests(register func(registry.Registry), cfg cliCfg) error { keepClustersOnTestFailure: cfg.debugEnabled, clusterID: cfg.clusterID, } - if err := runner.runHTTPServer(cfg.httpPort, os.Stdout); err != nil { + if err := runner.runHTTPServer(cfg.httpPort, os.Stdout, bindTo); err != nil { return err } diff --git a/pkg/cmd/roachtest/test_runner.go b/pkg/cmd/roachtest/test_runner.go index 80b38f976447..6af6ece6a820 100644 --- a/pkg/cmd/roachtest/test_runner.go +++ b/pkg/cmd/roachtest/test_runner.go @@ -1187,14 +1187,15 @@ func (r *testRunner) removeWorker(ctx context.Context, name string) { // runHTTPServer starts a server running in the background. // // httpPort: The port on which to serve the web interface. Pass 0 for allocating +// bindTo: The host/ip on which to bind. Leave empty to bind on all local ips // // a port automatically (which will be printed to stdout). -func (r *testRunner) runHTTPServer(httpPort int, stdout io.Writer) error { +func (r *testRunner) runHTTPServer(httpPort int, stdout io.Writer, bindTo string) error { http.HandleFunc("/", r.serveHTTP) // Run an http server in the background. // We handle the case where httpPort is 0, which means we automatically // allocate a port. - listener, err := net.Listen("tcp", fmt.Sprintf(":%d", httpPort)) + listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", bindTo, httpPort)) if err != nil { return err } @@ -1204,7 +1205,11 @@ func (r *testRunner) runHTTPServer(httpPort int, stdout io.Writer) error { panic(err) } }() - fmt.Fprintf(stdout, "HTTP server listening on all network interfaces, port %d.\n", httpPort) + bindToDesc := "all network interfaces" + if bindTo != "" { + bindToDesc = bindTo + } + fmt.Fprintf(stdout, "HTTP server listening on %s, port %d.\n", bindToDesc, httpPort) return nil }