2Make gRPC requests to the service.
4@sa @ref scripts/docs/en/userver/tutorial/grpc_service.md
15USERVER_CONFIG_HOOKS = [
'prepare_config_vars']
18@pytest.fixture(scope='session')
21 Returns the gRPC listener port number of the service that is set in the
22 static configuration file.
24 Override this fixture to change the way the gRPC listener port number
25 is retrieved by the testsuite for tests.
27 @ingroup userver_testsuite_fixtures
29 components = service_config_yaml[
'components_manager'][
'components']
30 if 'grpc-server' not in components:
31 raise RuntimeError(
'No grpc-server component')
32 return components[
'grpc-server'][
'port']
35@pytest.fixture(scope='session')
38 Returns the gRPC endpoint of the service.
40 Override this fixture to change the way the gRPC endpoint
41 is retrieved by the testsuite for tests.
43 @ingroup userver_testsuite_fixtures
45 return f
'localhost:{grpc_service_port}'
48@pytest.fixture(scope='session')
51 Returns the gRPC timeout for the service that is set by the command
52 line option `--service-timeout`.
54 Override this fixture to change the way the gRPC timeout
57 @ingroup userver_testsuite_fixtures
59 return float(pytestconfig.option.service_timeout)
or DEFAULT_TIMEOUT
62@pytest.fixture(scope='session')
63async def _grpc_session_channel(grpc_service_endpoint):
64 async with grpc.aio.insecure_channel(grpc_service_endpoint)
as channel:
70 grpc_service_endpoint,
73 _grpc_session_channel,
76 Returns the gRPC channel configured by the parameters from the
77 @ref plugins.grpc.grpc_service_endpoint "grpc_service_endpoint" fixture.
79 @ingroup userver_testsuite_fixtures
82 await asyncio.wait_for(
83 _grpc_session_channel.channel_ready(),
84 timeout=grpc_service_timeout,
86 except asyncio.TimeoutError:
88 f
'Failed to connect to remote gRPC server by '
89 f
'address {grpc_service_endpoint}',
91 return _grpc_session_channel
97 gRPC service dependencies hook. Feel free to override it.
99 @ingroup userver_testsuite_fixtures
103@pytest.fixture(scope=
'session')
104def prepare_config_vars(grpc_mockserver_endpoint):
105 def patch_config(config, config_vars):
106 for name
in config_vars:
107 if config_vars[name] ==
'$grpc_mockserver':
108 config_vars[name] = grpc_mockserver_endpoint