Beispiel #1
0
    def health_check_query(self):
        try:
            with grpc.insecure_channel(self._server_address) as channel:
                response = HealthStub(channel).Check(
                    health_pb2.HealthCheckRequest(service="DagsterApi"))
        except grpc.RpcError as e:
            print(e)  # pylint: disable=print-call
            return health_pb2.HealthCheckResponse.UNKNOWN  # pylint: disable=no-member

        status_number = response.status
        # pylint: disable=no-member
        return health_pb2.HealthCheckResponse.ServingStatus.Name(status_number)
Beispiel #2
0
    def test_server(self):
        from protos.blueprintservice_pb2_grpc import BlueprintServiceStub
        from protos.testmessage_pb2 import TestMessage
        from protos.user_pb2 import User

        with insecure_channel("0.0.0.0:50051") as channel:
            response = BlueprintServiceStub(channel).UnaryUnary(
                TestMessage(user=User(name="unary_unary")))
            self.assertEqual("unary_unary", response.user.name)
            self.assertEqual(1, self.app_process_request.call_count)
            self.assertEqual(1, self.app_process_response.call_count)
            self.assertEqual(1, self.blueprint_after_request.call_count)
            self.assertEqual(1, self.blueprint_before_request.call_count)

            for response in BlueprintServiceStub(channel).UnaryStream(
                    TestMessage(user=User(name="unary_stream"))):
                pass
            self.assertEqual("unary_stream", response.user.name)
            self.assertEqual(2, self.app_process_request.call_count)
            self.assertEqual(1, self.app_process_response.call_count)
            self.assertEqual(1, self.blueprint_after_request.call_count)
            self.assertEqual(2, self.blueprint_before_request.call_count)

            response = BlueprintServiceStub(channel).StreamUnary(
                iter([TestMessage(user=User(name="stream_unary"))]))
            self.assertEqual("stream_unary", response.user.name)
            self.assertEqual(2, self.app_process_request.call_count)
            self.assertEqual(2, self.app_process_response.call_count)
            self.assertEqual(2, self.blueprint_after_request.call_count)
            self.assertEqual(2, self.blueprint_before_request.call_count)

            for response in BlueprintServiceStub(channel).StreamStream(
                    iter([TestMessage(user=User(name="stream_stream"))])):
                pass
            self.assertEqual("stream_stream", response.user.name)
            self.assertEqual(2, self.app_process_request.call_count)
            self.assertEqual(2, self.app_process_response.call_count)
            self.assertEqual(2, self.blueprint_after_request.call_count)
            self.assertEqual(2, self.blueprint_before_request.call_count)

            self.assertEqual(
                1,
                HealthStub(channel).Check(HealthCheckRequest()).status)
            for response in ServerReflectionStub(channel).ServerReflectionInfo(
                    iter([ServerReflectionRequest(list_services="")])):
                self.assertEqual(
                    {
                        "service": [
                            {
                                "name": "AppService"
                            },
                            {
                                "name": "BlueprintService"
                            },
                            {
                                "name": "grpc.health.v1.Health"
                            },
                            {
                                "name":
                                "grpc.reflection.v1alpha.ServerReflection"
                            },
                        ]
                    },
                    MessageToDict(response.list_services_response),
                )

        self.assertEqual(4, self.enter_context.call_count)