From bef286f034497ae5b391e00a1046e7c178d4ad32 Mon Sep 17 00:00:00 2001
From: Ken Payson <kpayson@google.com>
Date: Thu, 16 Jun 2016 16:39:04 -0700
Subject: [PATCH] Wait for channel to be connected for each client

---
 src/python/grpcio/tests/qps/benchmark_client.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/python/grpcio/tests/qps/benchmark_client.py b/src/python/grpcio/tests/qps/benchmark_client.py
index 1b100bb168..080281415d 100644
--- a/src/python/grpcio/tests/qps/benchmark_client.py
+++ b/src/python/grpcio/tests/qps/benchmark_client.py
@@ -30,11 +30,13 @@
 """Defines test client behaviors (UNARY/STREAMING) (SYNC/ASYNC)."""
 
 import abc
+import threading
 import time
 
 from concurrent import futures
 from six.moves import queue
 
+import grpc
 from grpc.beta import implementations
 from grpc.framework.interfaces.face import face
 from src.proto.grpc.testing import messages_pb2
@@ -62,6 +64,13 @@ class BenchmarkClient:
     else:
       channel = implementations.insecure_channel(host, port)
 
+    connected_event = threading.Event()
+    def wait_for_ready(connectivity):
+      if connectivity == grpc.ChannelConnectivity.READY:
+        connected_event.set()
+    channel.subscribe(wait_for_ready, try_to_connect=True)
+    connected_event.wait()
+
     if config.payload_config.WhichOneof('payload') == 'simple_params':
       self._generic = False
       self._stub = services_pb2.beta_create_BenchmarkService_stub(channel)
-- 
GitLab