code: def test_sync_response_methods_fail_in_deployment(
      serve_instance, stream: bool
  ):
      """Blocking `DeploymentResponse` (and generator) methods should fail in loop."""
  
      if stream:
  
          @serve.deployment
          def downstream():
              yield
  
      else:
  
          @serve.deployment
          def downstream():
              pass
  
      @serve.deployment
      class Deployment:
          def __init__(self, handle: RayServeHandle):
              self._handle = handle.options(
                  use_new_handle_api=True, stream=stream
              )
  
          async def __call__(self):
              response = self._handle.remote()
              with pytest.raises(
                  RuntimeError,
                  match="should not be called from within an `asyncio` event loop",
              ):
                  if stream:
                      for _ in response:
                          pass
                  else:
                      response.result()
  
              return "OK"
  
      handle = serve.run(Deployment.bind(downstream.bind())).options(
          use_new_handle_api=True
      )
  
      assert handle.remote().result() == "OK"
  
file_path: ray/python/ray/serve/tests/test_new_handle_api.py
imports: import sys
  from typing import Any
  import pytest
  import ray
  from ray import serve
  from ray._private.test_utils import SignalActor
  from ray.serve.handle import DeploymentHandle, DeploymentResponse, DeploymentResponseGenerator, RayServeHandle, RayServeSyncHandle
label_desc: Use image node_id 9 for calling a global function with example usage: test_sync_response_methods_fail_in_deployment(serve_instance, stream) and returns: str