code: def test_deploy_with_partial_constructor_failure(serve_instance):
      # Test deploy with 2 replicas but one of them failed all
      # attempts
      with tempfile.TemporaryDirectory() as tmpdir:
          file_path = os.path.join(tmpdir, "test_deploy.txt")
  
          @serve.deployment(num_replicas=2)
          class PartialConstructorFailureDeployment:
              def __init__(self):
                  if not os.path.exists(file_path):
                      with open(file_path, "w") as f:
                          # Write first replica tag to local file so that it will
                          # consistently fail even retried on other actor
                          f.write(
                              serve.get_replica_context().replica_tag
                          )
                      raise RuntimeError(
                          "Consistently throwing on same replica."
                      )
                  else:
                      with open(file_path) as f:
                          content = f.read()
                          if (
                              content
                              == serve.get_replica_context().replica_tag
                          ):
                              raise RuntimeError(
                                  "Consistently throwing on same replica."
                              )
                          else:
                              return True
  
              async def serve(self, request):
                  return "hi"
  
          serve.run(PartialConstructorFailureDeployment.bind())
  
      # Assert 2 replicas are running in deployment deployment after partially
      # successful deploy call
      deployment_dict = ray.get(
          serve_instance._controller._all_running_replicas.remote()
      )
      deployment_id = DeploymentID(
          "PartialConstructorFailureDeployment", SERVE_DEFAULT_APP_NAME
      )
      assert len(deployment_dict[deployment_id]) == 2
  
file_path: ray/python/ray/serve/tests/test_constructor_failure.py
imports: import os
  import sys
  import tempfile
  import pytest
  import ray
  from ray import serve
  from ray.serve._private.common import DeploymentID
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
label_desc: Use image node_id 2 for calling a global function with example usage: test_deploy_with_partial_constructor_failure(serve_instance) and returns: str, True