code: def test_grpc_server():
      """Test `gRPCServer` did the correct overrides.
  
      When a add_servicer_to_server function is called on an instance of `gRPCServer`,
      it correctly overrides `response_serializer` to None, and `unary_unary` and
      `unary_stream` to be generated from the factory function.
      """
      service_name = "ray.serve.ServeAPIService"
      method_name = "ServeRoutes"
  
      def add_test_servicer_to_server(servicer, server):
          rpc_method_handlers = {
              method_name: grpc.unary_unary_rpc_method_handler(
                  servicer.ServeRoutes,
                  request_deserializer=AnyProto.FromString,
                  response_serializer=AnyProto.SerializeToString,
              ),
          }
          generic_handler = grpc.method_handlers_generic_handler(
              service_name, rpc_method_handlers
          )
          server.add_generic_rpc_handlers((generic_handler,))
  
      grpc_server = gRPCServer(
          thread_pool=None,
          generic_handlers=(),
          interceptors=(),
          options=(),
          maximum_concurrent_rpcs=None,
          compression=None,
          service_handler_factory=fake_service_handler_factory,
      )
      dummy_servicer = DummyServicer()
  
      # Ensure `generic_rpc_handlers` is not populated before calling
      # the add_servicer_to_server function.
      assert grpc_server.generic_rpc_handlers == []
  
      add_test_servicer_to_server(dummy_servicer, grpc_server)
  
      # `generic_rpc_handlers` should be populated after add_servicer_to_server is called.
      assert len(grpc_server.generic_rpc_handlers) == 1
  
      # The populated rpc handler should have the correct service name.
      rpc_handler = grpc_server.generic_rpc_handlers[0][0]
      assert rpc_handler.service_name() == service_name
  
      # The populated method handlers should have the correct response_serializer,
      # unary_unary, and unary_stream.
      service_method = f"/{service_name}/{method_name}"
      method_handlers = rpc_handler._method_handlers.get(service_method)
      assert method_handlers.response_serializer is None
      assert (
          method_handlers.unary_unary()
          == f"unary call from {service_method}".encode()
      )
      assert (
          method_handlers.unary_stream()
          == f"stream call from {service_method}".encode()
      )
  
file_path: ray/python/ray/serve/tests/unit/test_grpc_util.py
imports: import pickle
  from typing import Callable
  import grpc
  import pytest
  from google.protobuf.any_pb2 import Any
  from ray import cloudpickle
  from ray.serve._private.grpc_util import DummyServicer, create_serve_grpc_server, gRPCServer
  from ray.serve._private.test_utils import FakeGrpcContext
  from ray.serve.grpc_util import RayServegRPCContext
label_desc: Use image node_id 4 for calling a global function with example usage: test_grpc_server() without return types