diff --git a/benchmark/benchmark.go b/benchmark/benchmark.go index 542b33c2..df1493bc 100644 --- a/benchmark/benchmark.go +++ b/benchmark/benchmark.go @@ -92,10 +92,11 @@ func (s *testServer) StreamingCall(stream testpb.TestService_StreamingCallServer } } -// StartServer starts a gRPC server serving a benchmark service. It returns its -// listen address and a function to stop the server. -func StartServer() (string, func()) { - lis, err := net.Listen("tcp", ":0") +// StartServer starts a gRPC server serving a benchmark service on the given +// address, which may be something like "localhost:0". It returns its listen +// address and a function to stop the server. +func StartServer(addr string) (string, func()) { + lis, err := net.Listen("tcp", addr) if err != nil { grpclog.Fatalf("Failed to listen: %v", err) } diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go index 49d1cfd6..1c1d5739 100644 --- a/benchmark/benchmark_test.go +++ b/benchmark/benchmark_test.go @@ -15,7 +15,7 @@ import ( func runUnary(b *testing.B, maxConcurrentCalls int) { s := stats.AddStats(b, 38) b.StopTimer() - target, stopper := StartServer() + target, stopper := StartServer("localhost:0") defer stopper() conn := NewClientConn(target) tc := testpb.NewTestServiceClient(conn) @@ -58,7 +58,7 @@ func runUnary(b *testing.B, maxConcurrentCalls int) { func runStream(b *testing.B, maxConcurrentCalls int) { s := stats.AddStats(b, 38) b.StopTimer() - target, stopper := StartServer() + target, stopper := StartServer("localhost:0") defer stopper() conn := NewClientConn(target) tc := testpb.NewTestServiceClient(conn) diff --git a/benchmark/server/main.go b/benchmark/server/main.go index 747f9f3b..090f002f 100644 --- a/benchmark/server/main.go +++ b/benchmark/server/main.go @@ -28,7 +28,7 @@ func main() { grpclog.Fatalf("Failed to serve: %v", err) } }() - addr, stopper := benchmark.StartServer() + addr, stopper := benchmark.StartServer(":0") // listen on all interfaces grpclog.Println("Server Address: ", addr) <-time.After(time.Duration(*duration) * time.Second) stopper()