Browse Source

grpcproxy/cluster_test: serve grpc server after register service

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Gyu-Ho Lee 8 years ago
parent
commit
8a589d2d73
1 changed files with 9 additions and 4 deletions
  1. 9 4
      proxy/grpcproxy/cluster_test.go

+ 9 - 4
proxy/grpcproxy/cluster_test.go

@@ -107,15 +107,20 @@ func newClusterProxyServer(endpoints []string, t *testing.T) *clusterproxyTestSe
 	}
 	var opts []grpc.ServerOption
 	cts.server = grpc.NewServer(opts...)
-	go cts.server.Serve(cts.l)
-
-	// wait some time for free port 0 to be resolved
-	time.Sleep(500 * time.Millisecond)
+	servec := make(chan struct{})
+	go func() {
+		<-servec
+		cts.server.Serve(cts.l)
+	}()
 
 	Register(client, "test-prefix", cts.l.Addr().String(), 7)
 	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(servec)
+
+	// wait some time for free port 0 to be resolved
+	time.Sleep(500 * time.Millisecond)
 
 	return cts
 }