Exemple #1
0
 def setUp(self):
     self._client_execution_thread_pool = logging_pool.pool(1)
     self._fake_time = grpc_testing.strict_fake_time(time.time())
     self._real_time = grpc_testing.strict_real_time()
     self._fake_time_channel = grpc_testing.channel(
         rekcurd_pb2.DESCRIPTOR.services_by_name.values(), self._fake_time)
     self._real_time_channel = grpc_testing.channel(
         rekcurd_pb2.DESCRIPTOR.services_by_name.values(), self._real_time)
Exemple #2
0
    def setUp(self):
        # In this test the client-side application under test executes in
        # a separate thread while we retain use of the test thread to "play
        # server".
        self._client_execution_thread_pool = logging_pool.pool(1)

        self._fake_time = grpc_testing.strict_fake_time(time.time())
        self._real_time = grpc_testing.strict_real_time()
        self._fake_time_channel = grpc_testing.channel(
            services_pb2.DESCRIPTOR.services_by_name.values(), self._fake_time)
        self._real_time_channel = grpc_testing.channel(
            services_pb2.DESCRIPTOR.services_by_name.values(), self._real_time)
Exemple #3
0
    def setUp(self):
        # In this test the client-side application under test executes in
        # a separate thread while we retain use of the test thread to "play
        # server".
        self._client_execution_thread_pool = logging_pool.pool(1)

        self._fake_time = grpc_testing.strict_fake_time(time.time())
        self._real_time = grpc_testing.strict_real_time()
        self._fake_time_channel = grpc_testing.channel(
            services_pb2.DESCRIPTOR.services_by_name.values(), self._fake_time)
        self._real_time_channel = grpc_testing.channel(
            services_pb2.DESCRIPTOR.services_by_name.values(), self._real_time)
Exemple #4
0
def fixture_events_channel():
    yield grpc_testing.channel(
        [
            events_pb2.DESCRIPTOR.services_by_name['Events']
        ],
        grpc_testing.strict_real_time()
    )
Exemple #5
0
 def setup(self) -> None:
     self._real_time = grpc_testing.strict_real_time()
     self._real_time_channel = grpc_testing.channel(
         milvus_pb2.DESCRIPTOR.services_by_name.values(), self._real_time)
     self._servicer = milvus_pb2.DESCRIPTOR.services_by_name[
         'MilvusService']
     self._milvus = Milvus(channel=self._real_time_channel)
def run_client_test(service_name, method_name, test_method, stub_method_handlers, *args, **kwargs):
    fake_time = grpc_testing.strict_fake_time(
        time.time())
    channel = grpc_testing.channel(SERVICES[service_name].values(),
                                   fake_time)
    stub = get_stubs(service_name, channel)
    service = SERVICES[service_name][service_name]

    client_execution_thread_pool = logging_pool.pool(1)
    try:
        test_client_only = kwargs.pop('_test_client_only', None)
        application_future = client_execution_thread_pool.submit(
            test_method,
            stub, method_name, *args, **kwargs)

        # if the client method call is expected to raise exception before grpc call
        if test_client_only:
            pass  # do not simulate grpc response
        else:
            for stub_method_name, call_sig, handlers in stub_method_handlers:
                expected_requests, responses = handlers
                stub_method = service.methods_by_name[stub_method_name]
                verify_request(channel, stub_method, call_sig, expected_requests, responses)

        application_return_value = application_future.result()
        application_exception = application_future.exception()
        if application_exception:
            raise application_exception
        return application_return_value
    except Timeout:
        raise
    finally:
        client_execution_thread_pool.shutdown(False)
        del channel
Exemple #7
0
def _create_mock_client():
    # Create a stub instance (using a test channel) in order to derive a mock
    # from it with autospec enabled. Mocking TensorBoardWriterServiceStub itself
    # doesn't work with autospec because grpc constructs stubs via metaclassing.
    test_channel = grpc_testing.channel(service_descriptors=[],
                                        time=grpc_testing.strict_real_time())
    stub = data_provider_pb2_grpc.TensorBoardDataProviderStub(test_channel)
    return mock.create_autospec(stub)
    def setUp(self):
        service_descriptors = [
            groundstation_pb2.DESCRIPTOR.
            services_by_name['GroundStationService']
        ]
        self.test_channel = grpc_testing.channel(
            service_descriptors, grpc_testing.strict_real_time())

        self.tb = gr.top_block()
Exemple #9
0
def _create_mock_api_client():
    # Create a stub instance (using a test channel) in order to derive a mock
    # from it with autospec enabled. Mocking TensorBoardExporterServiceStub
    # itself doesn't work with autospec because grpc constructs stubs via
    # metaclassing.
    test_channel = grpc_testing.channel(service_descriptors=[],
                                        time=grpc_testing.strict_real_time())
    stub = export_service_pb2_grpc.TensorBoardExporterServiceStub(test_channel)
    mock_api_client = mock.create_autospec(stub)
    return mock_api_client
Exemple #10
0
def _create_mock_client():
    # Create a stub instance (using a test channel) in order to derive a mock
    # from it with autospec enabled. Mocking TensorBoardWriterServiceStub itself
    # doesn't work with autospec because grpc constructs stubs via metaclassing.
    test_channel = grpc_testing.channel(service_descriptors=[],
                                        time=grpc_testing.strict_real_time())
    stub = write_service_pb2_grpc.TensorBoardWriterServiceStub(test_channel)
    mock_client = mock.create_autospec(stub)
    fake_exp_response = write_service_pb2.CreateExperimentResponse(
        experiment_id="123", url="should not be used!")
    mock_client.CreateExperiment.return_value = fake_exp_response
    return mock_client
Exemple #11
0
    def setUp(self):
        self._client_execution_thread_pool = logging_pool.pool(1)

        # Builds a testing channel
        self._fake_channel = grpc_testing.channel(
            DESCRIPTOR.services_by_name.values(),
            grpc_testing.strict_real_time())
        self._build_channel_patcher = patch(
            'fedlearner_webconsole.rpc.client._build_channel')
        self._mock_build_channel = self._build_channel_patcher.start()
        self._mock_build_channel.return_value = self._fake_channel
        self._client = RpcClient(self._project_config, self._participant)

        self._mock_build_channel.assert_called_once_with(
            self._TEST_URL, self._TEST_AUTHORITY)
Exemple #12
0
 def test_create_with_mock_server(self):
     thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=1)
     fake_channel = grpc_testing.channel(
         key_value_pb2.DESCRIPTOR.services_by_name.values(),
         grpc_testing.strict_real_time())
     # Offload the request to another thread so we can use this thread to
     # fake the server-side results.
     result_future = thread_pool.submit(
         grpc_kv_client.create,
         "localhost:1234",
         "golden-retriever",
         "pancakes",
         channel=fake_channel)
     # Fake the server-side results.
     invocation_metadata, request, rpc = (fake_channel.take_unary_unary(
         _get_method("CreateRecord")))
     rpc.send_initial_metadata(())
     rpc.terminate(
         key_value_pb2.Record(name="golden-retriever", value="pancakes"),
         (), grpc.StatusCode.OK, "")
     # Ensure the client had the correct response.
     result = result_future.result()
     self.assertIsNone(result)
 def setUp(self):
   super(WstlTest, self).setUp()
   self.config = tools.default_config()
   self.config.TerminalInteractiveShell.simple_prompt = True
   self.shell = interactiveshell.TerminalInteractiveShell.instance(
       config=self.config)
   self._time = grpc_testing.strict_real_time()
   self._channel = grpc_testing.channel(
       wstlservice_pb2.DESCRIPTOR.services_by_name.values(), self._time)
   self.sample_hl7v2 = json.dumps("""
   {'ADT_A01': {'ACC': None,
     'AL1': [{'0': 'AL1',
       '1': '0',
       '2': {'1': 'AA'},
       '3': {'1': 'Z88.0',
          '2': 'Personal history of allergy to penicillin',
          '3': 'ZAL'},
       '4': {'1': 'SEVERE'},
       '5': ['Shortness of breath'],
       '6': None}],
     'ARV_1': None,
     'ARV_2': None,
     'DB1': None,
     'DRG': None}}""")
Exemple #14
0
def grpc_channel():
    return grpc_testing.channel([
        account_pb_v4.DESCRIPTOR.services_by_name['Account'],
        airdrop_pb_v4.DESCRIPTOR.services_by_name['Airdrop'],
        tx_pb_v4.DESCRIPTOR.services_by_name['Transaction'],
    ], grpc_testing.strict_real_time)
Exemple #15
0
def grpc_channel():
    return grpc_testing.channel([
        account_pb.DESCRIPTOR.services_by_name['Account'],
    ], grpc_testing.strict_real_time)