def test_unary_timeout( self, master_ar_process, valid_user_header, grpc_stub, mocker, repo_is_ee): if repo_is_ee: endpoint_id = 'grpcs://127.0.0.1:2379' else: endpoint_id = 'grpc://127.0.0.1:2379' mocker.send_command( endpoint_id=endpoint_id, func_name='always_stall', aux_data=3, ) with pytest.raises(grpc.RpcError) as e: request = grpc_endpoint_pb2.StringMessage(message="foo 123") grpc_stub.UnaryDoSomething( request, metadata=( ('authorization', valid_user_header['Authorization']), ), timeout=2 ) assert e.value.code() == grpc.StatusCode.DEADLINE_EXCEEDED
def test_unary_failed( self, master_ar_process, valid_user_header, grpc_stub, mocker, repo_is_ee): if repo_is_ee: endpoint_id = 'grpcs://127.0.0.1:2379' else: endpoint_id = 'grpc://127.0.0.1:2379' mocker.send_command( endpoint_id=endpoint_id, func_name='always_bork', aux_data=True, ) with pytest.raises(grpc.RpcError) as e: request = grpc_endpoint_pb2.StringMessage(message="foo 123") grpc_stub.UnaryDoSomething( request, metadata=( ('authorization', valid_user_header['Authorization']), ), ) assert e.value.code() == grpc.StatusCode.FAILED_PRECONDITION assert e.value.details() == "request borked per request"
def test_unary_unauthn(self, master_ar_process, grpc_stub): with pytest.raises(grpc.RpcError) as e: request = grpc_endpoint_pb2.StringMessage(message="foo 123") grpc_stub.UnaryDoSomething( request, ) assert e.value.code() == grpc.StatusCode.UNAUTHENTICATED assert "not authenticated" in e.value.details()
def test_unary_happy_path(self, master_ar_process, valid_user_header, grpc_stub): request = grpc_endpoint_pb2.StringMessage(message="foo 123") response = grpc_stub.UnaryDoSomething( request, metadata=( ('authorization', valid_user_header['Authorization']), ), ) assert request.message in response.message
def UnaryDoSomething(self, request, context): if self._get_context_data_f("always_bork"): log.debug("gRPC server is borking the unary request") status = status_pb2.Status( code=code_pb2.FAILED_PRECONDITION, message="request borked per request", ) context.abort_with_status(rpc_status.to_status(status)) elif self._get_context_data_f("always_stall"): stall_time = self._get_context_data_f("stall_time") log.debug( "gRPC server is stalling the unary request for `{}` seconds". format(stall_time)) time.sleep(stall_time) return grpc_endpoint_pb2.StringMessage( message="received: {}".format(request.message))