예제 #1
0
    def test_configure_consistency(self):
        _, server_port, socket = framework_common.get_socket()

        with _start_python_with_args(
                _SERVER_PATH,
            [f"--port={server_port}", f"--maintenance_port={server_port}"
            ]) as (server, server_stdout, server_stderr):
            # Send RPC to server to make sure it's running.
            logging.info("Sending RPC to server.")
            test_pb2_grpc.TestService.EmptyCall(empty_pb2.Empty(),
                                                f"localhost:{server_port}",
                                                insecure=True,
                                                wait_for_ready=True)
            logging.info("Server successfully started.")
            socket.close()
            _, stats_port, stats_socket = framework_common.get_socket()
            with _start_python_with_args(_CLIENT_PATH, [
                    f"--server=localhost:{server_port}",
                    f"--stats_port={stats_port}", f"--qps={_QPS}",
                    f"--num_channels={_NUM_CHANNELS}"
            ]) as (client, client_stdout, client_stderr):
                stats_socket.close()
                try:
                    self._assert_client_consistent(server_port, stats_port,
                                                   _QPS, _NUM_CHANNELS)
                except:
                    _dump_streams("server", server_stdout, server_stderr)
                    _dump_streams("client", client_stdout, client_stderr)
                    raise
                finally:
                    server.kill()
                    client.kill()
                    server.wait(timeout=_SUBPROCESS_TIMEOUT_SECONDS)
                    client.wait(timeout=_SUBPROCESS_TIMEOUT_SECONDS)
예제 #2
0
def _start_rpc(method: str, metadata: Sequence[Tuple[str, str]],
               request_id: int, stub: test_pb2_grpc.TestServiceStub,
               timeout: float, futures: Mapping[int, Tuple[grpc.Future,
                                                           str]]) -> None:
    logger.debug(f"Sending {method} request to backend: {request_id}")
    if method == "UnaryCall":
        future = stub.UnaryCall.future(messages_pb2.SimpleRequest(),
                                       metadata=metadata,
                                       timeout=timeout)
    elif method == "EmptyCall":
        future = stub.EmptyCall.future(empty_pb2.Empty(),
                                       metadata=metadata,
                                       timeout=timeout)
    else:
        raise ValueError(f"Unrecognized method '{method}'.")
    futures[request_id] = (future, method)
예제 #3
0
파일: methods.py 프로젝트: zwong91/grpc
 def EmptyCall(self, request, context):
     _maybe_echo_metadata(context)
     return empty_pb2.Empty()
예제 #4
0
파일: methods.py 프로젝트: zwong91/grpc
def _unimplemented_service(unimplemented_service_stub):
    response_future = (unimplemented_service_stub.UnimplementedCall.future(
        empty_pb2.Empty()))
    _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED)
예제 #5
0
파일: methods.py 프로젝트: zwong91/grpc
def _empty_unary(stub):
    response = stub.EmptyCall(empty_pb2.Empty())
    if not isinstance(response, empty_pb2.Empty):
        raise TypeError('response is of type "%s", not empty_pb2.Empty!' %
                        type(response))
예제 #6
0
 def EmptyCall(self, request, context):
     return empty_pb2.Empty()
예제 #7
0
async def _empty_unary(stub: test_pb2_grpc.TestServiceStub) -> None:
    response = await stub.EmptyCall(empty_pb2.Empty())
    if not isinstance(response, empty_pb2.Empty):
        raise TypeError('response is of type "%s", not empty_pb2.Empty!' %
                        type(response))
예제 #8
0
async def _unimplemented_service(stub: test_pb2_grpc.UnimplementedServiceStub):
    call = stub.UnimplementedCall(empty_pb2.Empty())
    await _expect_status_code(call, grpc.StatusCode.UNIMPLEMENTED)
예제 #9
0
 def EmptyCall(self, _: empty_pb2.Empty,
               context: grpc.ServicerContext) -> empty_pb2.Empty:
     return empty_pb2.Empty()
예제 #10
0
 def set_not_serving(self):
     self.call_unary_with_deadline(rpc='SetNotServing',
                                   req=empty_pb2.Empty(),
                                   log_level=logging.INFO)
예제 #11
0
 def EmptyCall(self, _: empty_pb2.Empty,
               context: grpc.ServicerContext) -> empty_pb2.Empty:
     context.send_initial_metadata((('hostname', self._hostname), ))
     return empty_pb2.Empty()