From 7bd871716dda50219556bcbfe18f84f8356304b5 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Thu, 16 Nov 2017 09:17:17 -0800 Subject: [PATCH] proxy/grpcproxy: wait until register before Serve It was fatal-ing with: grpclog.Fatalf("grpc: Server.RegisterService after Server.Serve for %q", sd.ServiceName) Signed-off-by: Gyu-Ho Lee --- proxy/grpcproxy/cluster_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 }