Context manager to run the gRPC server and yield a client for it.
(self)
| 51 | |
| 52 | @contextlib.contextmanager |
| 53 | def run(self): |
| 54 | """Context manager to run the gRPC server and yield a client for it.""" |
| 55 | server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) |
| 56 | grpc_util_test_pb2_grpc.add_TestServiceServicer_to_server(self, server) |
| 57 | port = server.add_secure_port( |
| 58 | "localhost:0", grpc.local_server_credentials() |
| 59 | ) |
| 60 | |
| 61 | def launch_server(): |
| 62 | server.start() |
| 63 | server.wait_for_termination() |
| 64 | |
| 65 | thread = threading.Thread(target=launch_server, name="TestGrpcServer") |
| 66 | thread.daemon = True |
| 67 | thread.start() |
| 68 | with grpc.secure_channel( |
| 69 | "localhost:%d" % port, grpc.local_channel_credentials() |
| 70 | ) as channel: |
| 71 | yield grpc_util_test_pb2_grpc.TestServiceStub(channel) |
| 72 | server.stop(grace=None) |
| 73 | thread.join() |
| 74 | |
| 75 | |
| 76 | class CallWithRetriesTest(tb_test.TestCase): |
no test coverage detected