Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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"
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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))