diff --git a/proxy/grpcproxy/cluster_test.go b/proxy/grpcproxy/cluster_test.go index 031a95684db3..b92316624336 100644 --- a/proxy/grpcproxy/cluster_test.go +++ b/proxy/grpcproxy/cluster_test.go @@ -107,7 +107,11 @@ func newClusterProxyServer(endpoints []string, t *testing.T) *clusterproxyTestSe } var opts []grpc.ServerOption cts.server = grpc.NewServer(opts...) - go cts.server.Serve(cts.l) + ready := make(chan struct{}) + go func() { + <-ready + cts.server.Serve(cts.l) + }() // wait some time for free port 0 to be resolved time.Sleep(500 * time.Millisecond) @@ -116,6 +120,7 @@ func newClusterProxyServer(endpoints []string, t *testing.T) *clusterproxyTestSe cts.cp, cts.donec = NewClusterProxy(client, cts.l.Addr().String(), "test-prefix") cts.caddr = cts.l.Addr().String() pb.RegisterClusterServer(cts.server, cts.cp) + close(ready) return cts }