Fix up client changes

pull/25142/head
Richard Belleville 4 years ago
parent c4d3fc749f
commit 0be354eb51
  1. 27
      src/python/grpcio_tests/tests_py3_only/interop/xds_interop_client.py

@ -44,6 +44,11 @@ _SUPPORTED_METHODS = (
"EmptyCall", "EmptyCall",
) )
_METHOD_CAMEL_TO_CAPS_SNAKE = {
"UnaryCall": "UNARY_CALL",
"EmptyCall": "EMPTY_CALL",
}
_METHOD_STR_TO_ENUM = { _METHOD_STR_TO_ENUM = {
"UnaryCall": messages_pb2.ClientConfigureRequest.UNARY_CALL, "UnaryCall": messages_pb2.ClientConfigureRequest.UNARY_CALL,
"EmptyCall": messages_pb2.ClientConfigureRequest.EMPTY_CALL, "EmptyCall": messages_pb2.ClientConfigureRequest.EMPTY_CALL,
@ -147,10 +152,11 @@ class _LoadBalancerStatsServicer(test_pb2_grpc.LoadBalancerStatsServiceServicer
response = messages_pb2.LoadBalancerAccumulatedStatsResponse() response = messages_pb2.LoadBalancerAccumulatedStatsResponse()
with _global_lock: with _global_lock:
for method in _SUPPORTED_METHODS: for method in _SUPPORTED_METHODS:
response.num_rpcs_started_by_method[method] = _global_rpcs_started.get[method] caps_method = _METHOD_CAMEL_TO_CAPS_SNAKE[method]
response.num_rpcs_succeeded_by_method[method] = _global_rpcs_succeeded.get[method] response.num_rpcs_started_by_method[caps_method] = _global_rpcs_started[method]
response.num_rpcs_failed_by_method[method] = _global_rpcs_succeeded.get[method] response.num_rpcs_succeeded_by_method[caps_method] = _global_rpcs_succeeded[method]
logger.info("Returning cumulative stats request.") response.num_rpcs_failed_by_method[caps_method] = _global_rpcs_failed[method]
logger.info("Returning cumulative stats response.")
return response return response
@ -184,8 +190,6 @@ def _on_rpc_done(rpc_id: int, future: grpc.Future, method: str,
else: else:
logger.error(exception) logger.error(exception)
else: else:
with _global_lock:
_global_rpcs_succeeded[method] += 1
response = future.result() response = future.result()
hostname = None hostname = None
for metadatum in future.initial_metadata(): for metadatum in future.initial_metadata():
@ -194,6 +198,12 @@ def _on_rpc_done(rpc_id: int, future: grpc.Future, method: str,
break break
else: else:
hostname = response.hostname hostname = response.hostname
if future.code() == grpc.StatusCode.OK:
with _global_lock:
_global_rpcs_succeeded[method] += 1
else:
with _global_lock:
_global_rpcs_failed[method] += 1
if print_response: if print_response:
if future.code() == grpc.StatusCode.OK: if future.code() == grpc.StatusCode.OK:
logger.info("Successful response.") logger.info("Successful response.")
@ -284,6 +294,7 @@ class _XdsUpdateClientConfigureServicer(test_pb2_grpc.XdsUpdateClientConfigureSe
def Configure(self, request: messages_pb2.ClientConfigureRequest, def Configure(self, request: messages_pb2.ClientConfigureRequest,
context: grpc.ServicerContext) -> messages_pb2.ClientConfigureResponse: context: grpc.ServicerContext) -> messages_pb2.ClientConfigureResponse:
logging.info("Received Configure RPC: {}".format(request))
method_strs = (_METHOD_ENUM_TO_STR[t] for t in request.types) method_strs = (_METHOD_ENUM_TO_STR[t] for t in request.types)
for method in _SUPPORTED_METHODS: for method in _SUPPORTED_METHODS:
method_enum = _METHOD_STR_TO_ENUM[method] method_enum = _METHOD_STR_TO_ENUM[method]
@ -293,10 +304,10 @@ class _XdsUpdateClientConfigureServicer(test_pb2_grpc.XdsUpdateClientConfigureSe
else: else:
qps = 0 qps = 0
metadata = () metadata = ()
channel_config = self._per_method_config[method] channel_config = self._per_method_configs[method]
with channel_config.condition: with channel_config.condition:
channel_config.qps = qps channel_config.qps = qps
channel_config.metadata = metadata channel_config.metadata = list(metadata)
channel_config.condition.notify_all() channel_config.condition.notify_all()
# TODO: Wait for all channels to respond until responding to RPC? # TODO: Wait for all channels to respond until responding to RPC?
return messages_pb2.ClientConfigureResponse() return messages_pb2.ClientConfigureResponse()

Loading…
Cancel
Save